-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Load method problem with composite key id
PostPosted: Fri Dec 05, 2003 5:04 am 
Newbie

Joined: Mon Dec 01, 2003 7:00 am
Posts: 16
Hi,
How to load an object which have composite id ?
I used session.load(object,id) method , but it doesn't work.

Throws following Exception

SEVERE: IllegalArgumentException in class: com.ge.med.registries.acc_30.hibernate.TCx1PtsiteT, getter method of property: Participant

But my TCx1PtsiteT class contain getter method of Participant

TCx1PtsiteT is defined in hbm file as follows

<class name="com.ge.med.registries.acc_30.hibernate.TCx1PtsiteT" proxy="com.ge.med.registries.acc_30.hibernate.TCx1PtsiteT" table="T_CX1_PtSite_T">
<composite-id unsaved-value="any" >
<key-many-to-one name="Participant" class="com.ge.med.registries.acc_30.hibernate.TCx1ParticipantM" column="Participant_ID"/>
<key-many-to-one name="Patient" class="com.ge.med.registries.acc_30.hibernate.TCx1PatientT" column="PatID"/>
</composite-id>
<one-to-one name="accPatient" class="com.ge.med.registries.acc_30.hibernate.TA3PatientT" constrained="true" outer-join="false"/>
<bag name="admParticipant" inverse="true" lazy="true" cascade="all">
<key column="Participant_ID"/>
<one-to-many class="com.ge.med.registries.acc_30.hibernate.TCx1AdmdisT"/>
</bag>
<bag name="admPatient" inverse="true" lazy="true" cascade="all">
<key column="PatID"/>
<one-to-many class="com.ge.med.registries.acc_30.hibernate.TCx1AdmdisT"/>
</bag>
</class>

Try to load object sess.load(site,new Long("33"));
At that point I get the Exception..

Can somebody can come up with the solution?

Devesh


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 6:05 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I suppose you need to pass instance of TCx1PtsiteT istead of Long to session.load()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 6:06 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Oh, sorry, not TCx1PtsiteT but instance of composite-id class


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 6:45 am 
Newbie

Joined: Mon Dec 01, 2003 7:00 am
Posts: 16
Hi,

As u said i did followin changes in code and run the class

participant.setPrimary("PARTID1ACC47");
patient.setPrimary(new Long("54"));
site.setPatient(patient);
site.setParticipant(participant);

tx = sess.beginTransaction();
sess.load(a3Patient,site);
tx.commit();

loaded instance of site object which contain patid and particpant id

Then also exception remain same.

Can u help me more


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 7:21 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
I'm a little confused with your code. Which class are you attempting to load? If it is TCx1PtsiteT, then why first parameter of load is named a3Patient? If you are loading Patient then why you use TCx1PtsiteT as its ID?. Please clarify


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 7:27 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You need you explicit a class attribute in your copposite-id. This class must be Serializable, override equals and hashcode etc...

Then use it as your id

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 7:46 am 
Newbie

Joined: Mon Dec 01, 2003 7:00 am
Posts: 16
I am trying to load a3Patient .
as u told to load instance of TCxptsite into load method.

Logically this is correct also , since site contain patID and ParticipantID
and a3Patient have one-to-one relationship ,it should load on basis of instance of site

But it doesn't work out.

I will try to include class in composite id and get back to u guys


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 7:51 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
If you are loading Patient, you do not need Site because I suppose your patient has some non-composite ID (I assume it is Long).

If Patient uses Long, its loading is very easy:

Code:
session.load(Patient.class, new Long(xxx));

or

Code:
Patient p = new Patient();
session.load(p, new Long(xxx));


Tricks are needed to load Site only because it uses composite-id


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 7:57 am 
Newbie

Joined: Mon Dec 01, 2003 7:00 am
Posts: 16
Wait ur getting Lost.

I want to load a3Patient not patient ok.
a3Patient have one-to-one relationship on composite id with ptSite table.
both ptsite and a3Patient doesn't not content primary key


Problem Exists here

To load a object which doesn't have primary key.
Object contain composite id

More clarificiation keep in loop


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.