-->
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: Nulls in composite-id
PostPosted: Fri Apr 22, 2005 12:17 pm 
Newbie

Joined: Thu Apr 21, 2005 7:25 am
Posts: 2
I have a problem after migrating to hibernate3 (3.0.1):
In an exsiting data model, I have a table without primary key. That's odd, but with hibernate2 it worked. With middlegen I generated a mapping file with a composite id using all columns. Read access via HQL statements worked fine.

Now with with hibernate3, the resulting list contains only nulls instead of the entity instances!!! After debugging, I found a code change in class ComponentType function hydrate(). The hibernate2 code was:

Code:
for ( int i=0; i<propertySpan; i++ ) {
    int length = propertyTypes[i].getColumnSpan( session.getFactory() );
    String[] range = ArrayHelper.slice(names, begin, length); //cache this
    Object val = propertyTypes[i].hydrate(rs, range, session, owner);
    if (val!=null) notNull=true;
    values[i] = val;
    begin+=length;
}


In hibernate3 it was changed to

Code:
for ( int i = 0; i < propertySpan; i++ ) {
      int length = propertyTypes[i].getColumnSpan( session.getFactory() );
      String[] range = ArrayHelper.slice( names, begin, length ); //cache this
      Object val = propertyTypes[i].hydrate( rs, range, session, owner );
      if ( val == null ) {
          if (isKey) return null; //different nullability rules for pk/fk
      }
      else {
          notNull = true;
      }
      values[i] = val;
      begin += length;
}


This means, if a value of a key column is null, the whole key is considered to be null!!??
In my case, the composite-id contains all columns of the table and some of them are nullable. When I try to load such an entity, a null in a column leads to a null key and this leads to null entities!

I know having a table without primary key is not a great data model, but this is an old existing model. And with hibernate2 it worked - this seemed to be a big migration issue.
Any comments, workarounds etc?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 12:56 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There can be no null fields in primary keys in the same way that you can't identify something in the real world if the thing you have to identify it with is missing. Fix your database.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 1:03 pm 
Newbie

Joined: Thu Apr 21, 2005 7:25 am
Posts: 2
Hello Christian,

thanks for your quick reply.
This means, that tables without primary keys and nullable columns are no more supported by hibernate3? With hibernate2 it worked...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 22, 2005 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, it didn't work, you were just slowly destroying your data with duplicates. There can be no nullable column in a primary key.


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.