-->
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: Hibernate Criteria, on association, createCriteria, createAl
PostPosted: Tue Oct 18, 2011 5:13 am 
Newbie

Joined: Mon Jan 05, 2009 5:25 pm
Posts: 8
Hi

I "have" two classes:

Code:
class A {
   B b; // can be null
   Boolean gender;
}

class B extends Person { // Person contains firstName, lastName ...
  String name;
}

c = session.createCriteria(A.class)
Criteria bc = c.createCriteria("b"); // Adding this forces B to be not null and the search will exclude A's that have a B that is null. How can I overcome this, I want to be able to search on b's properties and its superclasses ?

c.list();

"Solution" 1:
add an OR for isNull and isNotNull on bc. However, I also want the user to be able to specify just one of the two. I could propably do that first, however that is an ugly solution.

"Solution" 2:
Do not createCriteria or createAlias, but use dotted syntax b.name when you add restrictions. Sure that works, however when searching on the superclass Person, that wont work and will require createCriteria or createAlias.

Is there a way to create a sub accosiation notation that do not force the association to be not null.

// Thanks Hamidam


Top
 Profile  
 
 Post subject: Re: Hibernate Criteria, on association, createCriteria, createAl
PostPosted: Tue Oct 18, 2011 5:28 am 
Newbie

Joined: Mon Jan 05, 2009 5:25 pm
Posts: 8
I think I figured it out. Using InnerJoin on the createAlias seems to achieve that.


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.