Discussion:
[Middlegen-user] Clash with CMP and CMR fields in JBoss
M-Leander Reimer
2002-07-01 12:22:28 UTC
Permalink
Hi,
I came across a problem with Middlegen samples + JBoss 3.0.0 + mySQL and
I could need some advice.

Basically, it is not allowed in JBoss to declare a CMR field also as a
CMP field. The Hypersonic DB in JBoss doens't complain, but mySQL does.
What happens is that the generated create table statement has a
duplicate column name for all foreign key fields. The solution to it is
(from JBoss forum) not to declare the foreign key fields as CMP.

The question is: How do I change Middlegen appropriately? I changed the
Velocity template not to include the setter/getter methods (and the
ejb:persistent tag) for all foreign key columns. Is this OK that way??

Is it still possible to have a compound primary key (like it is in the
Reservation table) without declaring the CMP fields for the foreign
keys?

Thanks for your help!

Leander
Aslak Hellesøy
2002-07-02 16:17:37 UTC
Permalink
-----Original Message-----
M-Leander Reimer
Sent: 1. juli 2002 16:15
Subject: [Middlegen-user] Clash with CMP and CMR fields in JBoss
Hi,
I came across a problem with Middlegen samples + JBoss 3.0.0 + mySQL and
I could need some advice.
Basically, it is not allowed in JBoss to declare a CMR field also as a
CMP field. The Hypersonic DB in JBoss doens't complain, but mySQL does.
What happens is that the generated create table statement has a
duplicate column name for all foreign key fields. The solution to it is
(from JBoss forum) not to declare the foreign key fields as CMP.
Can you point me to where/who said this? I don't think the EJB 2.0 mandates
this, and I suspect this to be a JBoss limitation.
The question is: How do I change Middlegen appropriately? I changed the
Velocity template not to include the setter/getter methods (and the
ejb:persistent tag) for all foreign key columns. Is this OK that way??
I have committed an update which makes it possible to turn off CMP
generation for CMR fields:
<cmp20 fkcmp="false"/>
Is it still possible to have a compound primary key (like it is in the
Reservation table) without declaring the CMP fields for the foreign
keys?
Unfortunately not. See section 10.8.2 third paragraph of the EJB 2.0 spec:

"The names of the fields in the primary key class must be a subset of the
names of the container-managed
fields. (This allows the container to extract the primary key fields from an
instance’s container-managed
fields, and vice versa.)"
Thanks for your help!
Leander
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
M-Leander Reimer
2002-07-03 04:54:03 UTC
Permalink
Hi there,

I found a post on the JBoss forums in the "Database, Persistence, JBoss
CMP" forum, topic "duplicate column names - revisited" and following.

http://www.jboss.org/forums/thread.jsp?forum=46&thread=11566&message=2327625&q=duplicate+columns+created#2327625

There they describe that JBoss tries to create 2 fields with the same
name for the foreign key column, and that you only need to declare the
field as CMR to solve this problem.

Thanks for the merge file stuff, terminology confused me indeed. This
solution is a lot cleaner than putting the file reading code into the
plugin like it was in the patch.

Leander

Loading...