-->
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.  [ 6 posts ] 
Author Message
 Post subject: One-to-One loading problem
PostPosted: Mon Dec 15, 2003 7:08 am 
Newbie

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

When I try to load child using parent which have one-to-one relationship , it throws an exception.

My hbm looks like this

<class name="TCx1PtsiteT" proxy="TCx1PtsiteT" table="T_CX1_PtSite_T">
<composite-id name="comp_id" class="TCx1PtsiteTPK">
<key-many-to-one name="tcx1PatientT" class="TCx1PatientT" >
<column name="PatID" />
</key-many-to-one>
<key-many-to-one name="tcx1ParticipantM" class="TCx1ParticipantM">
<column name="Participant_ID" />
</key-many-to-one>
</composite-id>
<one-to-one name="accPatient" class="TA3PatientT" constrained="true" outer-join="false"/>
<bag name="tcxAdmDisTs" lazy="true" inverse="true" >
<key>
<column name="PatID" />
<column name="Participant_ID" />
</key>
<one-to-many class="TCx1AdmdisT"/>
</bag>
</class>

<class name="TA3PatientT" table="a3.T_A3_Patient_T">
<composite-id name="comp_id" class="TA3PatientTPK">
<key-many-to-one name="tcx1ptsitet" class="TCx1PtsiteT">
<column name="PatID"/>
<column name="Participant_ID" />
</key-many-to-one>
</composite-id>
<one-to-one name="ptSite" class="TCx1PtsiteT" constrained="false" outer-join="false"/>
<property name="race" column="Race" type="short" length="5"/>
</class>

In Java class i try to retrive TA3PatientT value like this

TCx1PtsiteT site = new TCx1PtsiteT();
site.getAccPatient()


It gives me following Exception :-

SEVERE: Failed to lazily initialize a collection
java.lang.ClassCastException
at TA3PatientTPKMetaClass0.getPropertyValues(<generated>)
at net.sf.hibernate.type.ComponentType.getPropertyValues(ComponentType.java:199)
at net.sf.hibernate.type.ComponentType.nullSafeGetValues(ComponentType.java:173)
at Retrive.main(Retrive.java:81)
rethrown as net.sf.hibernate.PropertyAccessException: exception getting property
value with CGLIB getter of TA3PatientTPK.?


I am not able to figure it out can anybody help me out

Devesh


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
One-to-one relationship impose both side to have the same id value (please read the doc in this subject). Your composite-id doesnt have the same structure, so having the same value is impossible. There are some post on this subject some days ago

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:32 am 
Newbie

Joined: Mon Dec 01, 2003 7:00 am
Posts: 16
My database table is something like this :

Table TCx1PtsiteT - consist of two compoiste key which have
Many - to - one relationship with TCx1PatientT and TCx1ParticipantM

which can be represented like this in hbm

<composite-id name="comp_id" class="TCx1PtsiteTPK" unsaved-value="any">
<key-many-to-one name="tcx1PatientT" class="TCx1PatientT" >
<column name="PatID" />
</key-many-to-one>
<key-many-to-one name="tcx1ParticipantM" class="TCx1ParticipantM">
<column name="Participant_ID" />
</key-many-to-one>
</composite-id>

and Table TA3PatientT contain two compoiste id which have one-to-one relationship with TCx1PtsiteT

<composite-id name="comp_id" class="TA3PatientTPK">
<key-many-to-one name="tcx1ptsitet" class="TCx1PtsiteT">
<column name="PatID"/>
<column name="Participant_ID" />
</key-many-to-one>
</composite-id>

Can u figure it out where i have to make the changes ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Types contained in <composite-id> should be the same (ie TCx1PtsiteTPK for both)
I *strongly* recommend you to use surrogate keys instead of natural one. It'll be far more easier to do.

If you can't change you object model, consider using a many-to-one or a one-to-one with property-ref attribute (never play with that but should be ok). Property-ref is a 2.1 feature.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:53 am 
Newbie

Joined: Mon Dec 01, 2003 7:00 am
Posts: 16
Can u just give me some link which tells about property-ref ?
In my case what will be property-ref value ?
In document nothing has been specified about property-ref .

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:09 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
section 5.1.11
Actually, as I told you I don't play that much with composite keys so I can't really help you. Maybe someone else has experience on that.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.