-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to use left joins with class mappings (many-to-one)
PostPosted: Sat Jan 03, 2004 6:51 pm 
Newbie

Joined: Sat Jan 03, 2004 6:34 pm
Posts: 3
I'm working w/legacy data.
One table (A) has a foreign key (with possible empty string values) that maps to a row on another table (B)
Here are the mappings:

(A)
<hibernate-mapping>
<class name="com.amdr.business.model.A table="A">
<cache usage="read-only"/>
<composite-id>
<key-property name="idcodapli"></key-property>
<key-property name="nocod"></key-property>
<key-property name="state"></key-property>
<key-property name="date"></key-property>
</composite-id>
<many-to-one name="reason" column="idReason" not-null="false" class="com.amdr.business.model.B" outer-join="true" />
</hibernate-mapping>

(B)
<hibernate-mapping>
<class name="com.amdr.business.model.B" table="B" >
<id name="idReason" type="string" >
<generator class="assigned"></generator>
</id>
<property column="Description" length="60" name="descripcion" type="string"/>
</class>
</hibernate-mapping>

(the name of the FK in A matchs the name of the PK in B)
Whenever I try to load rows from A I get:
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: " " (empty string) , of class: com.amdr.business.model.B

I need to load thoose values (from B) whenever the FK is not empty.
In sql I achieve this by using LEFT JOIN.

I'd appreciate any help.
Thnx in advance.
-stn


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 03, 2004 7:27 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Can't you use NULLs instead of empty string value?
Empty string is a valid string and it is just refering to record with empty string ID in another table.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 03, 2004 8:02 pm 
Newbie

Joined: Sat Jan 03, 2004 6:34 pm
Posts: 3
i'm working with legacy data.
I suppose that I could convert empty string values to null.
But if I can get what I want in SQL/HQL with LEFT JOIN I guess is possible with class mapping. Am I wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 04, 2004 1:46 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
stn wrote:
But if I can get what I want in SQL/HQL with LEFT JOIN I guess is possible with class mapping. Am I wrong?

I don't think this is doable. As dimas pointed, "" is a valid FK. Even with 2 SQL statement instead of LEFT JOIN, Hibernate will try to load A with "" PK and fail.

_________________
Emmanuel


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