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.  [ 7 posts ] 
Author Message
 Post subject: Can I create a disjunction across collections using QBE?
PostPosted: Sat Mar 12, 2005 12:24 pm 
Newbie

Joined: Sat Mar 12, 2005 12:01 pm
Posts: 8
I'm putting together a demo for my coworkers to show them why we should move our mixed EJB 1.1/EJB 2.1 app to hibernate during our JBoss conversion. Part of this demo will be a QBE demo.

I have three simple classes:

Person
String firstName
String lastName
Set addresses (relates to Address)
Email email (relates to Email )

Address
String line1, line2 etc...

Email
String email ...


Using QBE, it was shockingly easy to get a simple AND scenario setup:

Person p = new Person();
p.setFirstName("D");

Address a = new Address();
a.setCity("St");

Email e = new Email();
e.setEmail("dc");

Example personExample = Example.create(p)
.ignoreCase()
.enableLike(MatchMode.START);

Example addressExample = Example.create(a).ignoreCase().enableLike(MatchMode.START);

Example emailExample = Example.create(e).ignoreCase().enableLike(MatchMode.START);


//create a criteria based on a person
Criteria personCriteria = session.createCriteria(Person.class).add(personExample);

//add an address criteria, using the name of the property this is related to
personCriteria.createCriteria("addresses").add(addressExample);

//add an email criteria, using the name of the email property
personCriteria.createCriteria("email").add(emailExample);


The query this creates is perfect for matching ALL properties.

Now, what I'd like do do is create a Disjunction on addresses and email, so it will return objects that macth the properties of Person AND (the properties of Address OR the properties of Email).

Can this be done only using QBE?
Thanks,
Dave Cracauer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 12, 2005 12:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
org.hibernate.criterion.Disjunction

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 13, 2005 11:53 am 
Newbie

Joined: Sat Mar 12, 2005 12:01 pm
Posts: 8
I have tried using Disjunction, and am not able to make it work using the Example object I created.

When I do this:

Junction dis= Expression.disjunction().add(addressExample).add(emailExample);

Criteria personCriteria = session.createCriteria(Person.class).add(personExample).add(dis);

Hibernate throws a net.sf.hibernate.PropertyAccessException

I assume this is because it is looking for the Address and Email properties (in the Example object, in the Disjuction) on the Person object.

I can't figure out how to properly create a Disjunction of two Example objects that are properties of another object.


Thanks,
Dave


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 13, 2005 3:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - without being the biggest Critiera wizard then try looking
into createAlias() to allow referring to more than one thing.

Also look at CriteriaQueryTest for inspiration.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: I am having the same problem.
PostPosted: Wed Mar 23, 2005 3:33 pm 
Newbie

Joined: Wed Feb 23, 2005 11:57 am
Posts: 15
I am having the same problem.

I need to create a disjunction of subqueries. You can only add Criterion (not Criteria) to a disjunction.

Let me know if you figure out how to do that with aliases.

Thanks,
gabe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 28, 2005 8:22 am 
is this really the case?

I too need to create a disjunction between two criteria. It appears impossible using the criteria API because the disjunction (or the Restrictions.or) will only take criterion.

Would be interested in any feedback.


Top
  
 
 Post subject:
PostPosted: Sun Jan 22, 2006 9:42 am 
Beginner
Beginner

Joined: Sun Jan 22, 2006 6:56 am
Posts: 29
treehugger wrote:
is this really the case?

I too need to create a disjunction between two criteria. It appears impossible using the criteria API because the disjunction (or the Restrictions.or) will only take criterion.

Would be interested in any feedback.


What about rewriting the subquery using Subqueries.exists ? It returns a Criterion.


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