-->
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: composite id null property
PostPosted: Tue Aug 28, 2007 3:04 pm 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
Hibernate version:3

Mapping documents:

<hibernate-mapping package="pack">
<class name="A" table="A">
<composite-id name="Apk" class="A_Pk">
<key-property name="grId" column="GRID"/>
<key-property name="vid" column="VID"/>
<key-property name="note" column="NOTE"/>
</composite-id>

</class>
</hibernate-mapping>

I also have a primary key class named A-Pk which implements serializble and also has all the primary key properties of A.

Code between sessionFactory.openSession() and session.close():

Query query =sess.createQuery("Select A from A a where a.apk.vid = "2+ "and a.apk.grId = 5");
Full stack trace of any exception that occurs:
Now If there is not null value of each of the columns in the A table I get desirable results . but the place where I have NOTE as null . I get null object back. I get the right number of objects but all those objects are null.
Where as what I want is that it should return the right number of objects with right property values. If one of the column has null value, it should return null value for that column but not for the whole object.
As I read in the docs , they say all the properties in the composite key should be not-null incase you are using "Set" but otherwise its fine.
Now Im using a list and it should be fine with that.
Can anybody help?
Any possible way out?


Top
 Profile  
 
 Post subject: Re: composite id null property
PostPosted: Tue Aug 28, 2007 4:01 pm 
Beginner
Beginner

Joined: Mon Aug 27, 2007 8:10 am
Posts: 37
sriguru wrote:
Hibernate version:3

Can anybody help?
Any possible way out?


I know there were some issues on composite ID which claimed to be fixed in v. 3.1.3


Top
 Profile  
 
 Post subject: should note be part of the composite ID?
PostPosted: Tue Aug 28, 2007 8:19 pm 
Newbie

Joined: Mon Aug 27, 2007 11:11 pm
Posts: 8
Location: Brisbane
I had exactly the same issue where I put a column in the composite id that could be null. I moved it outside the composite-id and just made it a normal property and that fixed the issue. The database generally doesn't allow a null in a primary key column anyway so it makes sense that if a column can be null then it shouldn't be in the composite-key. I guess there's always a use case for having a null in the composite-id but maybe you can live with moving it outside the composite-id?


Top
 Profile  
 
 Post subject: thanks
PostPosted: Wed Aug 29, 2007 1:57 pm 
Beginner
Beginner

Joined: Fri May 11, 2007 11:03 am
Posts: 32
Thanks guys it helped. I realised that we cant have nullable column in composite key.
Anyways I had to apply the logic programmatically.
Thanks for help
Cheers!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 21, 2007 11:26 am 
Newbie

Joined: Sun Nov 04, 2007 8:11 pm
Posts: 4
So ... what does one do if one needs to return a list of unordered/maybe duplicated records from database?

Given Hibernate:
1: Always need a ID for class mapping
2. Cannot have null in composite-id

I'd be surprised if this will seem an impossible task for Hibernate !?

regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 31, 2009 2:36 am 
Beginner
Beginner

Joined: Wed Aug 22, 2007 5:53 am
Posts: 38
How can i take a property out of <composite-id> ?
Code:
<class name="ProductBasicBO" table="TBPRODUCTPERIOD">
<composite-id name="compProductBasicBO" class="com.tietoenator.lis.db.impl.product.bo.CompProductBasicBO">
  <key-property name="productId" column="PRODUCTID" ></key-property>
         <key-property name="useType" column="USETYPE"></key-property>
         <key-property name="startTimeStamp" column="STARTTIMESTAMP" ></key-property>
      </composite-id>
</class>


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.