-->
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: intentional nulls in composite-id
PostPosted: Wed Jun 09, 2004 10:53 am 
Newbie

Joined: Wed Jun 09, 2004 10:45 am
Posts: 7
Location: Philadelphia, PA
I'm currently evaluating hibernate and trying to map it to some preexisting database tables. It's going quite well but I've come aacross an interesting problem...

I've got this table that has about 6 columns in the composite-id.
The group of 6 when combined must be unique.
Each of the fields may be null. That is a valid case.
I need to be able to query the table using a where referenceing any column. But, when I do this, hibernate runs my query ok, gets a result and tries to load the non-key fields by running a subsequent query using the key values found in the first query. Some of these fields are null and it fails to find the matching row.

Is this a case where hibernate won't be a good fit?
If hibernate can do this, I'll need some help.

Thanks a bunch
Carl


Top
 Profile  
 
 Post subject: Re: intentional nulls in composite-id
PostPosted: Wed Jun 09, 2004 12:55 pm 
Newbie

Joined: Wed Jun 09, 2004 10:45 am
Posts: 7
Location: Philadelphia, PA
It seems that I can get results from this sort of query if I use query.list() instead of query.iterate(). Now I have conserns that I probably won't be able to update rows where key fields are null. I'm not sure but I'm going to give it a try.

Carl


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 1:58 pm 
Newbie

Joined: Wed Jun 09, 2004 10:45 am
Posts: 7
Location: Philadelphia, PA
As I expected, I am not able to update the objects returned in the query.list() call.
The update statement executes and I get no errors, but the data isn't changed because no record matched the where clause.
the where clause looks like where field1 = ? and field2 = ?....
But, since some of the values are null, it's not doing the right thing.
Is there a way to fix this? I know, don't have nulls in your key fields. Not my choice right now.
Perhaps the update-sql feature. Is that in the latest source? I'll have to build hibernate?

Enyone?

Thanks
Carl


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 2:06 pm 
Newbie

Joined: Wed Jun 09, 2004 10:45 am
Posts: 7
Location: Philadelphia, PA
Ideally what I'd be looking for is the where clause that hibernate generates to look more like.... field1 = ? and field2 is null and fie...

Perhaps something I'll have to write?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 09, 2004 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Null's as possible in elements of the composite key - OUCH bad. You should change the schema. Although you will say the powers will not allow you to.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 10, 2004 8:57 am 
Newbie

Joined: Wed Jun 09, 2004 10:45 am
Posts: 7
Location: Philadelphia, PA
Exactly right, I'm working with an existing database structure and don't have that flexibility.

After looking through the hibernate source and actually stepping through it with a debugger, I think I will not be going to hibernate soon. The where clause that selects an object by the id is pretty fixed at being just = ?. And the code that writes this sql doesn't readily have visibility to the id values to test them for null.

Maybe someday I'll manage to return to hibernate, but for now it looks like I'm stuck with bean managed persistence.

Thanks
Carl


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.