-->
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.  [ 2 posts ] 
Author Message
 Post subject: many-to-one with null association
PostPosted: Mon Feb 15, 2010 12:42 am 
Newbie

Joined: Wed May 28, 2008 3:56 pm
Posts: 18
I have a many-to-one association which can also be nullable.

[code]
<many-to-one name="secondWorkLocation" class="com.hibernate.SecondWorkLocation" not-null="false" fetch="select" not-found="ignore">
<column name="LOCATION_ID" precision="22" scale="0"/>
</many-to-one>
[/code]


Wheneven my hibernate query (below) tries to retrieve the records it works for a employee record which has secondworklocation but fails to return any data when there is no second work location.

[code]
List<Employees> results = null;
DetachedCriteria crit = DetachedCriteria.forClass(Employees.class);
crit.add(Restrictions.eq("employeeId", employee.getEmployeeId()));
results = getHibernateTemplate().findByCriteria(crit);
[/code]

[code]
CREATE TABLE "TESTDB"."EMPLOYEES" (... "LOCATION_ID" NUMBER(38 , 0))
ALTER TABLE "TESTDB"."EMPLOYEES" ADD CONSTRAINT "EMPLOYEES_FK1" FOREIGN KEY ("LOCATION_ID")
REFERENCES "TESTDB"."SECOND_WORK_LOCATION" ("LOCATION_ID")
[/code]

Is there any syntactic error in my many to one mapping ?


Top
 Profile  
 
 Post subject: Re: many-to-one with null association
PostPosted: Mon Feb 15, 2010 10:10 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
I have used the same mapping and used hibernate query.
It is working fine for me.

So problem must be somewhere else.

Can you see the sql generated?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.