-->
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.  [ 1 post ] 
Author Message
 Post subject: Can HQL handle nullable foreign keys in relationships?
PostPosted: Fri Dec 12, 2008 6:06 pm 
Newbie

Joined: Tue Mar 27, 2007 12:25 pm
Posts: 3
I have a table with a nullable foreign key column. A value will be set when someone updates the record later, but all records start out with this field null.

When I try to do a join from this table using the nullable foreign key Hibernate throws a null pointer exception. That's probably because the parent object is null in some cases, but that's the point of a nullable foreign key. Here's my HQL:

select new com.pas.dao.CorrectionPendingElement(
m.bizId, cp.id, cp.clinicalCondition, cp.correctionLevel, cp.correctiveAction, cp.submittedDate, cp.submitterUserAccess.userBizId, cp.submitterUserAccess.userName, cp.resolutionComment, cp.resolutionDate, resolverName)
from CorrectionPending cp, Member m left outer join cp.resolverUserAccess.userBizId as resolverName
where cp.member.bizId in
('...', '...', '...')
and cp.resolutionDate is null

(I've replaced the actual Ids with ...)

The CorrectionsPending table has a ResolverUserAccessId column which forms the <many-to-one ...> relationship with the UserAccess table, and ResolverUserAccessId starts out null.

I checked the mapping documents and for <many-to-one ..> it shows a "not-null" attribute but says that it is optional and is used by tools that generate DDL with nullability constraints. It sounds like it would not make Hibernate aware that the field cp.resolverUserAccess could be null and therefore Hibernate should not attempt to resolve cp.resolverUserAccess.userBizId.

Nullable foreign keys are a fairly common thing. I would think there is a way to handle them in Hibernate, but I haven't found anything yet that indicates that HQL can look out for them.

Has anyone found a way to do this in HQL?

Thanks.

Dean


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.