-->
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.  [ 5 posts ] 
Author Message
 Post subject: Criteria API null property problem
PostPosted: Thu Mar 15, 2007 8:09 am 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
Table 1(Object 1)

ID Foreign_Key
---------------
1 1
2 NULL



Table 2(Object 2)

ID somefield
-------------
1 somevalue



ICriteria object1Criteria = session.CreateCriteria(typeof(Object1));
ICriteria object2Criteria = object1Criteria.CreateCriteria(Typeof(Object2));

object1Criteria.Add(Expression ID to be 1);

IList result = object1Criteria.List();

WORKS OK


ICriteria object1Criteria = session.CreateCriteria(typeof(Object1));
ICriteria object2Criteria = object1Criteria.CreateCriteria(Typeof(Object2));

object1Criteria.Add(Expression ID to be 2);

IList result = object1Criteria.List();

DOES NO WORK BECAUSE foreign key field is null and I have created criteria on that property.


I need to create criteria on every Object1 property (that is Object type).
How to tell object2Criteria that although Object2 is NULL the query should return Object1 with ID1.

What is the solution?

Thanks!


Last edited by daffest on Thu Mar 15, 2007 4:14 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:09 am 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
Or else, my problem will solve if you tell me, how to check if Disjunction or Conjunction is empty (no expressions added).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:18 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I am not an expert in the Criteria API but I think you can define the fetching strategy on the createCriteria method for object2. You will have to tell hibernate that you want to do a left outer join.

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 10:25 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
See here http://www.hibernate.org/hib_docs/v3/ap ... ing,%20int) for more explanations (use left_join in your case)

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 3:57 pm 
Newbie

Joined: Thu Mar 15, 2007 8:07 am
Posts: 7
Can anyone tell me, how to set jointype in nhibernate 1.0.2.0 ?

There are several examples but there is no overload on CreateCriteria method that takes jointype as parameter in my nhibernate version.


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