Discussion:
[Middlegen-user] Double PK field trouble with EJB CMP2.0 composite PK in CMR/CMP clash
Kristoffer Moe
2002-10-02 12:19:41 UTC
Permalink
This problem may or may not have anything to do with middlegen, but is in
any case as follows:

Three tables A, B, C have bi-directional 1:n relationship between A and B,
ditto between B and C. Tables A and C have single attribute PKs, but B has
compound PK, composed of foreign keys to A and C tables' PK's. In effect,
this is a m:n relationship between A and C, with som additional information
(ie a description) attached to table B.

Result is that entity bean for B gets FK/PK fields acting both as CMR and
CMP fields. Rules are approx. as follows: 1) a CMR field is read-only in
ejbCreate(...), but may be set in ejbPostCreate(...), which is what
middlegen-generated code does 2) PK fields must be set by ejbCreate(...),
otherwise weblogic refuses to create bean. Since the setXXX methods in this
case are the same for PK fields and CMR fields, an attempt to call CMP
setXX in ejbCreate is denied, since it is assumed to be a CMR set, which is
not allowed. Also, since the table has no id attribute by itself which can
be auto-counted or whatever, there is only possible to create an instance
by supplying already extisting A and B beans. In other words, it is not
possible to first create a B and then attach an A and C afterwards.

Any ideas?


Regards,


Kristoffer Moe
Senior Consultant
Elan It ReSource
Aslak Hellesøy
2002-10-02 18:44:50 UTC
Permalink
-----Original Message-----
Kristoffer Moe
Sent: 2. oktober 2002 16:17
Subject: [Middlegen-user] Double PK field trouble with EJB CMP2.0
composite PK in CMR/CMP clash
This problem may or may not have anything to do with middlegen, but is in
Three tables A, B, C have bi-directional 1:n relationship between A and B,
ditto between B and C. Tables A and C have single attribute PKs, but B has
compound PK, composed of foreign keys to A and C tables' PK's. In effect,
this is a m:n relationship between A and C, with som additional
information
(ie a description) attached to table B.
So it's *exactly* like the airline sample, then. Did you look at that?
Result is that entity bean for B gets FK/PK fields acting both as CMR and
CMP fields. Rules are approx. as follows: 1) a CMR field is read-only in
ejbCreate(...), but may be set in ejbPostCreate(...), which is what
middlegen-generated code does 2) PK fields must be set by ejbCreate(...),
otherwise weblogic refuses to create bean. Since the setXXX
methods in this
case are the same for PK fields and CMR fields, an attempt to call CMP
setXX in ejbCreate is denied, since it is assumed to be a CMR
set, which is
not allowed. Also, since the table has no id attribute by itself which can
be auto-counted or whatever, there is only possible to create an instance
by supplying already extisting A and B beans. In other words, it is not
possible to first create a B and then attach an A and C afterwards.
Any ideas?
Create A and C first and then create B ;-)
-or ask on http://newsgroups.bea.com/
Regards,
Kristoffer Moe
Senior Consultant
Elan It ReSource
-------------------------------------------------------
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
Kristoffer Moe
2002-10-02 19:09:04 UTC
Permalink
snippysnippy
Post by Aslak Hellesøy
So it's *exactly* like the airline sample, then. Did you look at that?
Yes, it probably is very much like the airline example. I've discussed this
with Eivind today, and we figured out it would probably be a good idea to
try to deploy the airline app to weblogic, and see if the problem
reincarnates there. Placed on personal TODO list, though.
Post by Aslak Hellesøy
Post by Kristoffer Moe
Result is that entity bean for B gets FK/PK fields acting both as CMR
and CMP fields. Rules are approx. as follows: 1) a CMR field is
snip snip snip>
Post by Aslak Hellesøy
Create A and C first and then create B ;-)
-or ask on http://newsgroups.bea.com/
This is actually what is done, and it has been verified that A and C both
are assigned valid id's from autogenerator, so the problem is that the ids
(PK's) are never transferred to the PK fields of the PK class of bean C,
probably due to the CMR/CMP confusion.

However, I got around the problem by giving the B table its own autonumber
PK, though conceptually not neccessary. As a consequence, my ORM model is
somewhat messed up. I can live with that for now, though.



Regards,


Kristoffer Moe
Senior Consultant
Elan It ReSource
Eivind Waaler
2002-10-03 06:53:03 UTC
Permalink
Allright, I've deployed the airline sample on Weblogic 7.0, SQL Server
8. Seems like we actually get the same problem there. I added the
following code to the InsertReservationAction:

PersonLocal personLocal = ...
FlightLocal flightLocal = ...

ReservationLocal reservation = ReservationUtil.getLocalHome().create(
reservationForm.getRegistrationUtc(),
reservationForm.getComment(),
personLocal,
flightLocal
);

Testing of this on Weblogic ends in the following:

<03.okt.02 10:29:17 CEST> <Error> <HTTP> <101046>
<[ServletContext(id=3401671,name=airline-web.war,context-path=/airline)]
ActionServlet: Create error
javax.ejb.CreateException: In EJB Reservation, primary key field
'flightIdFk' was not set during ejbCreate. All primary key fields must be
initialized during ejbCreate.
at
airline.ejb.ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.pkCheck(ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.java:2207)
at
airline.ejb.ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.ejbCreate(ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.java:2259)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:737)
at
weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:716)
at
weblogic.ejb20.internal.EntityEJBLocalHome.create(EntityEJBLocalHome.java:182)
at
airline.ejb.ReservationCMP_1qdy24_LocalHomeImpl.create(ReservationCMP_1qdy24_LocalHomeImpl.java:97)
...

I'm sure we had this bean working som months ago on the cvs version of
middlegen at the time. That was however WLS6.1 I used back then.

Is this a Middlegen problem, xdoclet problem or weblogic 7.0
problem?? Anyone got it working? I just can't see what's wrong with this
bean...

.eivind

snippysnippy
Post by Aslak Hellesøy
So it's *exactly* like the airline sample, then. Did you look at that?
Yes, it probably is very much like the airline example. I've discussed
this
with Eivind today, and we figured out it would probably be a good idea
to
try to deploy the airline app to weblogic, and see if the problem
reincarnates there. Placed on personal TODO list, though.
Post by Aslak Hellesøy
Post by Kristoffer Moe
Result is that entity bean for B gets FK/PK fields acting both as CMR
and CMP fields. Rules are approx. as follows: 1) a CMR field is
snip snip snip>
Post by Aslak Hellesøy
Create A and C first and then create B ;-)
-or ask on http://newsgroups.bea.com/
This is actually what is done, and it has been verified that A and C both
are assigned valid id's from autogenerator, so the problem is that the
ids
(PK's) are never transferred to the PK fields of the PK class of bean C,
probably due to the CMR/CMP confusion.

However, I got around the problem by giving the B table its own
autonumber
PK, though conceptually not neccessary. As a consequence, my ORM model is
somewhat messed up. I can live with that for now, though.



Regards,


Kristoffer Moe
Senior Consultant
Elan It ReSource
a***@netcom.no
2002-10-03 08:57:02 UTC
Permalink
----- Original Message -----
From: Eivind Waaler <***@tihlde.org>
Date: Thursday, October 3, 2002 9:52 am
Subject: [Middlegen-user] RE: Double PK field trouble with EJB CMP2.0
composite PK in CMR/CMP clash
Post by Eivind Waaler
Allright, I've deployed the airline sample on Weblogic 7.0, SQL Server
8. Seems like we actually get the same problem there. I added the
PersonLocal personLocal = ...
FlightLocal flightLocal = ...
ReservationLocal reservation = ReservationUtil.getLocalHome().create(
reservationForm.getRegistrationUtc(),
reservationForm.getComment(),
personLocal,
flightLocal
);
<03.okt.02 10:29:17 CEST> <Error> <HTTP> <101046>
<[ServletContext(id=3401671,name=airline-web.war,context-
pathActionServlet: Create error
javax.ejb.CreateException: In EJB Reservation, primary key field
'flightIdFk' was not set during ejbCreate. All primary key fields
must be
initialized during ejbCreate.
at
airline.ejb.ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.pkCheck
(ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.java:2207)
Post by Eivind Waaler
at
airline.ejb.ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.ejbCreate
(ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.java:2259)
Post by Eivind Waaler
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:737)
at
weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:716)
at
weblogic.ejb20.internal.EntityEJBLocalHome.create
(EntityEJBLocalHome.java:182)
Post by Eivind Waaler
at
airline.ejb.ReservationCMP_1qdy24_LocalHomeImpl.create
(ReservationCMP_1qdy24_LocalHomeImpl.java:97)
Post by Eivind Waaler
...
I'm sure we had this bean working som months ago on the cvs
version of
middlegen at the time. That was however WLS6.1 I used back then.
Is this a Middlegen problem, xdoclet problem or weblogic 7.0
problem?? Anyone got it working? I just can't see what's wrong
with this
bean...
I don't know what the EJB spec says about this. Anyone? It's definitely
not an XDoclet problem. It's a WLS problem, but maybe Middlegen can
work around it?

What if the ejbCreate methods that take CMR/CMP fields as this example
does the following:

ejbCreate(..., PersonLocal person, ...) {
setPersonIdFk( person.getPersonId() );
}

-in addition to or in stead of calling the CMR setter in ejbPostCreate
()? Eivind, can you try that?

I don't know if JBoss or other containers would like this, so maybe
we're facing app-server-specific java code here. We should try to avoid
that, but if it's the only solution, let's go for it.

/Aslak
Post by Eivind Waaler
.eivind
snippysnippy
Post by Aslak Hellesøy
So it's *exactly* like the airline sample, then. Did you look
at that?
Yes, it probably is very much like the airline example. I've
discussedthis
with Eivind today, and we figured out it would probably be a
good idea
to
try to deploy the airline app to weblogic, and see if the problem
reincarnates there. Placed on personal TODO list, though.
Post by Aslak Hellesøy
Post by Kristoffer Moe
Result is that entity bean for B gets FK/PK fields acting both
as CMR
and CMP fields. Rules are approx. as follows: 1) a CMR field is
snip snip snip>
Post by Aslak Hellesøy
Create A and C first and then create B ;-)
-or ask on http://newsgroups.bea.com/
This is actually what is done, and it has been verified that A
and C both
are assigned valid id's from autogenerator, so the problem is
that the
ids
(PK's) are never transferred to the PK fields of the PK class of
bean C,
probably due to the CMR/CMP confusion.
However, I got around the problem by giving the B table its own
autonumber
PK, though conceptually not neccessary. As a consequence, my ORM
model is
somewhat messed up. I can live with that for now, though.
Regards,
Kristoffer Moe
Senior Consultant
Elan It ReSource
-------------------------------------------------------
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
Kristoffer Moe
2002-10-03 09:20:02 UTC
Permalink
Post by a***@netcom.no
----- Original Message -----
Post by Eivind Waaler
middlegen at the time. That was however WLS6.1 I used back then.
snip snip
Post by a***@netcom.no
Post by Eivind Waaler
Is this a Middlegen problem, xdoclet problem or weblogic 7.0
problem?? Anyone got it working? I just can't see what's wrong
with this
bean...
I don't know what the EJB spec says about this. Anyone? It's definitely
not an XDoclet problem. It's a WLS problem, but maybe Middlegen can
work around it?
What if the ejbCreate methods that take CMR/CMP fields as this example
ejbCreate(..., PersonLocal person, ...) {
setPersonIdFk( person.getPersonId() );
}
Actually, we have tried this (in my specific problem, though), and the
result is a protest from weblogic stating that these fields are read-only
in ejbCreate, since they are CMR fields.

Regards,


Kristoffer
Eivind Waaler
2002-10-04 04:18:01 UTC
Permalink
Post by a***@netcom.no
----- Original Message -----
Date: Thursday, October 3, 2002 9:52 am
Subject: [Middlegen-user] RE: Double PK field trouble with EJB CMP2.0
composite PK in CMR/CMP clash
Post by Eivind Waaler
Allright, I've deployed the airline sample on Weblogic 7.0, SQL Server
8. Seems like we actually get the same problem there. I added the
PersonLocal personLocal = ...
FlightLocal flightLocal = ...
ReservationLocal reservation = ReservationUtil.getLocalHome().create(
reservationForm.getRegistrationUtc(),
reservationForm.getComment(),
personLocal,
flightLocal
);
<03.okt.02 10:29:17 CEST> <Error> <HTTP> <101046>
<[ServletContext(id=3401671,name=airline-web.war,context-
pathActionServlet: Create error
javax.ejb.CreateException: In EJB Reservation, primary key field
'flightIdFk' was not set during ejbCreate. All primary key fields
must be
initialized during ejbCreate.
at
airline.ejb.ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.pkCheck
(ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.java:2207)
Post by Eivind Waaler
at
airline.ejb.ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.ejbCreate
(ReservationCMP_1qdy24__WebLogic_CMP_RDBMS.java:2259)
Post by Eivind Waaler
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:737)
at
weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:716)
at
weblogic.ejb20.internal.EntityEJBLocalHome.create
(EntityEJBLocalHome.java:182)
Post by Eivind Waaler
at
airline.ejb.ReservationCMP_1qdy24_LocalHomeImpl.create
(ReservationCMP_1qdy24_LocalHomeImpl.java:97)
Post by Eivind Waaler
...
I'm sure we had this bean working som months ago on the cvs
version of
middlegen at the time. That was however WLS6.1 I used back then.
Is this a Middlegen problem, xdoclet problem or weblogic 7.0
problem?? Anyone got it working? I just can't see what's wrong
with this
bean...
I don't know what the EJB spec says about this. Anyone? It's definitely
not an XDoclet problem. It's a WLS problem, but maybe Middlegen can
work around it?
What if the ejbCreate methods that take CMR/CMP fields as this example
ejbCreate(..., PersonLocal person, ...) {
setPersonIdFk( person.getPersonId() );
}
-in addition to or in stead of calling the CMR setter in ejbPostCreate
()? Eivind, can you try that?
Yes this works. The CMR setters in ejbPostCreate() must be removed,
otherwise you get an error since these are read only when part of the
primary key.

I submitted a bug report as I'm not entirely sure how to fix this the best
way. Also don't know if this works with JBoss..

.eivind
Post by a***@netcom.no
I don't know if JBoss or other containers would like this, so maybe
we're facing app-server-specific java code here. We should try to avoid
that, but if it's the only solution, let's go for it.
/Aslak
Post by Eivind Waaler
.eivind
snippysnippy
Post by Aslak Hellesøy
So it's *exactly* like the airline sample, then. Did you look
at that?
Yes, it probably is very much like the airline example. I've
discussedthis
with Eivind today, and we figured out it would probably be a
good idea
to
try to deploy the airline app to weblogic, and see if the problem
reincarnates there. Placed on personal TODO list, though.
Post by Aslak Hellesøy
Post by Kristoffer Moe
Result is that entity bean for B gets FK/PK fields acting both
as CMR
and CMP fields. Rules are approx. as follows: 1) a CMR field is
snip snip snip>
Post by Aslak Hellesøy
Create A and C first and then create B ;-)
-or ask on http://newsgroups.bea.com/
This is actually what is done, and it has been verified that A
and C both
are assigned valid id's from autogenerator, so the problem is
that the
ids
(PK's) are never transferred to the PK fields of the PK class of
bean C,
probably due to the CMR/CMP confusion.
However, I got around the problem by giving the B table its own
autonumber
PK, though conceptually not neccessary. As a consequence, my ORM
model is
somewhat messed up. I can live with that for now, though.
Regards,
Kristoffer Moe
Senior Consultant
Elan It ReSource
-------------------------------------------------------
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
Loading...