File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes CMR and composite foriegn key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMR and composite foriegn key" Watch "CMR and composite foriegn key" New topic
Author

CMR and composite foriegn key

Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
We have a table say A for which two columns constitute primary key col-a and say col-b.
A has one to many relationship to another table X. Both the above said colulmns are there in table X and have foreign key constraint to table A.
We are getting exceptions when we try to set the collection of entity X to entity A, since the foreign keys are not automatically updated.
Basic quetion is does CMR works for composite foreign keys??
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

yes


Groovy
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
When we try to call addAll() on the collection , the container throws a null pointer exception.
On a side note for a composite primary key, can u tell me what is a good hashcode implementation? coz I think that also may be the problem
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

http://developer.java.sun.com/developer/Books/effectivejava/Chapter3.pdf
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
Here is the error that we are getting when adding an enity threshold to another entity Adjustments
Adjustment table has two columns as the primary key(the class AdjustmentPK) and hence these are also foreign keys in threshold. It throws an exception whenever we are trying to add a threshold refernce to adjustment..
Most of the code is generated by the ejbgen tool

java.lang.NullPointerException
at com.circuitcity.vma.ejb.pa.local.AdjustmentsPK.hashCode(AdjustmentsPK
.java:26)
at com.circuitcity.vma.ejb.pa.local.AdjustmentsPK.equals(AdjustmentsPK.j
ava:43)
at com.circuitcity.vma.ejb.pa.local.PAAdjustmentsEntityBean_5r9txz__WebL
ogic_CMP_RDBMS_threshHolds_Set.add(PAAdjustmentsEntityBean_5r9txz__WebLogic_CMP_
RDBMS_threshHolds_Set.java:282)
at com.circuitcity.vma.ejb.pa.helper.PAAdjustmentEntityHelper.updateThre
shHold(PAAdjustmentEntityHelper.java:115)
at com.circuitcity.vma.ejb.pa.helper.PAAdjustmentEntityHelper.create(PAA
djustmentEntityHelper.java:86)
at com.circuitcity.vma.ejb.pa.helper.PAAdjustmentEntityHelper.create(PAA
djustmentEntityHelper.java:57)
at com.circuitcity.vma.ejb.pa.helper.PAEntityHelper.updateAdjustments(PA
EntityHelper.java:121)
at com.circuitcity.vma.ejb.pa.local.PASessionFacade.updateAdjustments(PA
SessionFacade.java:97)
at com.circuitcity.vma.ejb.pa.local.PASessionFacade_8sw7cg_EOImpl.update
Adjustments(PASessionFacade_8sw7cg_EOImpl.java:154)
at com.circuitcity.vma.ejb.pa.local.PASessionFacade_8sw7cg_EOImpl_WLSkel
.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:362)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:114)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:313)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:785)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:308)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:153)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:134)
error...null
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
well, we found the error .. the ejbgen tool has generated the primary key class in which the hashcode method used to give null pointer exception since the objct on which the method is called is null before the container sets the relationship fields!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CMR and composite foriegn key