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
|