-->
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: Query by example returning wrong entities
PostPosted: Fri Sep 09, 2005 8:58 am 
Newbie

Joined: Wed Jun 01, 2005 6:18 am
Posts: 9
When querying for orders, the collection returned is a collection of customers, even though when the criteria is created it it is told that we want Orders.

This worked under hibernate 2, and stopped working after upgrading.

Example exampleOrd = Example.create(ord).excludeZeroes().enableLike(MatchMode.ANYWHERE)..ignoreCase();
Example exampleCust = exampleCust = Example.create(cust).excludeZeroes().enableLike(MatchMode.ANYWHERE).ignoreCase();

Criteria x = session.createCriteria(Order.class);
x.add(exampleOrd);
x.createCriteria("customer").add(exampleCust);

List<Order> orders = x.list();

This returns a List<Customer> when it should return a List<Order>. If I remove the example customer from the criteria, it returns a List<Order> as it should..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 10:37 am 
Newbie

Joined: Wed Jun 01, 2005 6:18 am
Posts: 9
I've been assured this is not a bug, can anyone explain this behaviour?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 11:24 am 
Newbie

Joined: Thu Sep 11, 2003 11:49 am
Posts: 8
Location: Albuquerque NM
I think you have a problem with the semicolons. You have:

Criteria x = session.createCriteria(Order.class);
x.add(exampleOrd);
x.createCriteria("customer").add(exampleCust);

Try:

Criteria x = session.createCriteria(Order.class)
.add(exampleOrd);
.createCriteria("customer")
.add(exampleCust);

HTH


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 11:26 am 
Newbie

Joined: Thu Sep 11, 2003 11:49 am
Posts: 8
Location: Albuquerque NM
Should be:

Criteria x = session.createCriteria(Order.class)
.add(exampleOrd)
.createCriteria("customer")
.add(exampleCust);

(I also had a semicolon problem)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 11:28 am 
Newbie

Joined: Wed Jun 01, 2005 6:18 am
Posts: 9
Thanks. Only prob is, the addition of a customer / order example to the criteria is within a condition. So it is necessary to have the satements seperate rather than together in one.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 11:43 am 
Newbie

Joined: Thu Sep 11, 2003 11:49 am
Posts: 8
Location: Albuquerque NM
Could you create an Example on the order.getCustomer() versus creating an Example on the cust? Is the cust definded as: cust = order.getCustomer()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 11:44 am 
Newbie

Joined: Wed Jun 01, 2005 6:18 am
Posts: 9
I've actually tried setting the customer example in the order pojo, didn't fix it.

Also removing the semi-colons doesn't fix it either.

Thanks for the suggestions though, worth a try.


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.