-->
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: @EmbeddedId and null field
PostPosted: Mon Dec 28, 2009 12:59 pm 
Newbie

Joined: Mon Dec 28, 2009 12:46 pm
Posts: 2
Hi everybody,
I'm using Hibernate 3.3.2 with Oracle 10g.
I have a table A without primary key defined (don't tell me why, legacy system...).
A has 14 fields, so hb2ddl tool created two Classes: A and AId, where the latter is the set of all the table's fields. Among these fields, only 3 have the not null constraint.
The problem is: whenever I query the table, Hibernate finds the correct number of tuples, but if one ore more fields of a tuple were null, the entity is not instantiated and the criteria.list() return List has a null entry.

Does anybody can tell me why?

Here is an example taken from the logs (TRACE level). If CAPTION is not null I have
Code:
16:52:15,421 DEBUG AbstractBatcher:426 - about to open ResultSet (open ResultSets: 0, globally: 0)
16:52:15,423 TRACE BigDecimalType:193 - returning '2' as column: ALLINEAM1_0_0_
16:52:15,424 TRACE StringType:193 - returning 'column caption bla bla' as column: CAPTION0_0_
16:52:15,424 TRACE BigDecimalType:193 - returning '0' as column: COLINDEX0_0_
16:52:15,424 TRACE StringType:193 - returning 'colonnanome' as column: COLNAME0_0_
16:52:15,425 TRACE BigDecimalType:193 - returning '1' as column: COLORDER0_0_
16:52:15,425 TRACE BigDecimalType:193 - returning '2' as column: COLWIDTH0_0_

then more fields until the entity is created


If CAPTION is null
Code:
16:53:15,779 DEBUG AbstractBatcher:426 - about to open ResultSet (open ResultSets: 0, globally: 0)
16:53:15,781 TRACE BigDecimalType:193 - returning '2' as column: ALLINEAM1_0_0_
16:53:15,781 TRACE StringType:187 - returning null as column: CAPTION0_0_
16:53:15,784 DEBUG AbstractBatcher:433 - about to close ResultSet (open ResultSets: 1, globally: 1)
16:53:15,784 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:53:15,784 TRACE AbstractBatcher:562 - closing statement


So at the first NULL met, the tuples seems to be abandoned

The table data type are all numbers or char or varchar, so the JPA entities have nothing in particular.
Any help would be really appreciated!
Thanks,
Ariminum


Top
 Profile  
 
 Post subject: Re: @EmbeddedId and null field
PostPosted: Tue Dec 29, 2009 5:55 am 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
I think it should not be possible to have nullable fields in an composite primary key. SQL Server complains to me every time I try to create a table like that.

How would you identify two tuples that have the same values and both have null in the nullable column? If that exists the column is not useful as a primary key => use only the not-null columns as primary key...


Top
 Profile  
 
 Post subject: Re: @EmbeddedId and null field
PostPosted: Tue Dec 29, 2009 1:46 pm 
Newbie

Joined: Mon Dec 28, 2009 12:46 pm
Posts: 2
Hi kossmo,
thanks for your reply.
I totally agree with you: from a relational point of view, this is completely wrong, but I cannot change the db schema (old vb6 applications using it...)
What I was asking myself is if I forgot something, because Hibernate does not give any error or warning, so I was worried about it.
Now I solved specifying in the reveng.xml a <primary-key> based on two non nullable fields.
Paolo


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.