-->
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.  [ 3 posts ] 
Author Message
 Post subject: empty strings as null
PostPosted: Fri Feb 20, 2004 12:31 pm 
Newbie

Joined: Fri Feb 20, 2004 12:15 pm
Posts: 8
Hi,

I am dealing with a legacy database where I need to map a many-to-one relation onto a table with a composite key.

The problem is that my composite key holds an empty string and a int equals to 0 for null values. When I load the many side table Hibernate tells me:
Code:
No row with the given identifier exists: ams.hibernate.BomPK@c48b77[bomId=,bomVer=0], of class: ams.hibernate.Bom; nested exception is net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: ams.hibernate.BomPK@c48b77[bomId=,bomVer=0], of class: ams.hibernate.Bom


Here is the many-to-one side mapping definition

Code:
    <!-- bi-directional many-to-one association to Bom -->
    <many-to-one
        name="bom"
        class="ams.hibernate.Bom"
        not-null="true"
    >
        <column name="bom_id" />
        <column name="bom_ver" />
    </many-to-one>



Here is the one side mapping definition

Code:
    <composite-id name="comp_id" class="ams.hibernate.BomPK">
        <key-property
            name="bomId"
            column="bom_id"
            type="java.lang.String"
            length="15"
        />
        <key-property
            name="bomVer"
            column="bom_ver"
            type="java.lang.Integer"
            length="4"
        />
    </composite-id>   


Any easy way to fix this ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 12:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably use two custom UserTypes for the properties which map 0 / the empty string to null.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 4:06 pm 
Newbie

Joined: Fri Feb 20, 2004 12:15 pm
Posts: 8
Thanks for the trick, I did not think of that.

But since I can have valid keys with a non empty String and a int at 0, should'nt I code the whole key class as a new type ?

I'm just not too sure on how to do that ? Would that be a CollectionUserType ?


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