Discussion:
[Middlegen-user] Problem with MiddleGen-Generated Bean Code
Michael Kashambuzi
2002-08-25 18:13:03 UTC
Permalink
Hi:

I'm having problems with source code generated by Middlegen. I'm using
the latest source code from CVS with Jboss 3.0 and MySQL v3.23 running
with InnoDB.

I have a basic problem with a parent and a child table.

Middlegen generated the ChildBean.java file but fails to generate the
setter method for the parent object.

Below is the DDL for the database tables.

DROP TABLE IF EXISTS parent;
DROP TABLE IF EXISTS child;

CREATE TABLE parent(
parent_id INT NOT NULL,
PRIMARY KEY( parent_id ),
INDEX parent_ind(parent_id)
) TYPE=INNODB;

CREATE TABLE child(
child_id INT NOT NULL,
parent_id_fk INT NOT NULL,
PRIMARY KEY( child_id ),
INDEX child_ind(child_id),
INDEX parent_ind(parent_id_fk),
FOREIGN KEY (parent_id_fk) REFERENCES parent(parent_id)
) TYPE=INNODB;



Below is the problematic-generated code for ChildBean.java. There is no
setParent() method defined anywhere as called in the ejbPostCreate
method defined below.

/**
* The container invokes thos method immediately after it calls
ejbCreate.
*
* @param childId the childId value
* @param firstName the firstName value
* @param lastName the lastName value
* @param parent mandatory CMR field
*/
public void ejbPostCreate( java.lang.Integer childId,
indref.interfaces.ParentLocal parent ) throws javax.ejb.CreateException {
// Set CMR fields
setParent(parent);
}

and here is the relevant middelegen task from my build.xml file adapted
from the Middlegen Airline sample.

<!--
=================================================================== -->
<!-- Run
Middlegen -->
<!--
=================================================================== -->
<target
name="middlegen"
description="Run Middlegen"
unless="middlegen.skip"
depends="check-driver-present,panic-if-driver-not-present"
<mkdir dir="${build.gen-src.dir}"/>

<taskdef
name="middlegen"
classname="middlegen.MiddlegenTask"
classpathref="lib.class.path"
/>

<middlegen
appname="${name}"
prefsdir="${src.dir}"
gui="${gui}"
databaseurl="${database.url}"
initialContextFactory="${java.naming.factory.initial}"
providerURL="${java.naming.provider.url}"
datasourceJNDIName="${name}.database"
driver="${database.driver}"
username="${database.userid}"
password="${database.password}"
<!--
We can specify what tables we want EJBs generated for.
If none are specified, EJBs will be generated for all tables.
Comment out the <table> elements if you want to generate for
all tables.
Also note that table names are case sensitive for certain
databases.
-->
<table name="parent" pktable="parent"/>
<table name="child" pktable="child"/>

<cmp20
destination="${build.gen-src.dir}"
package="${name}.ejb"
interfacepackage="${name}.interfaces"
jndiprefix="${unique.name}"
generatepk="true"
dataobject="true"
viewtype="local"
readonly="false"
fkcmp="true"
suffix=""
<!--
EJB containers can be specified here. They add aditional
features and perform additional validations. You don't have to
add them, they just provide "goodies".
-->
<weblogic pkgen="false"/>
<jboss/>
</cmp20>

</middlegen>

<mkdir dir="${build.classes.dir}"/>
</target>

How and where is Middlegen meant to generate the setParent(parent)
method for the ChildBean class?

Michael

Loading...