-->
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.  [ 4 posts ] 
Author Message
 Post subject: QuerybyExample using parent object with other entity objects
PostPosted: Fri Jan 27, 2006 2:57 pm 
Newbie

Joined: Fri Jan 27, 2006 1:18 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1

I want to search an entity object that has other entity objects as children (In a one to many relationship). Below is an example of what I more of less have. Since the search will have multi-criteria, it made sense for me to use the qbe.

Code:
public class Parent implements Serializable
{
    private Integer id;
    private String name;
    private List addresses;
    private List children; (of type Child)
    ...
}

public class Child
{
     private Integer id;
     private String name;
     ...
}

For searching the method looks something like this.
public Collection search(Parent parent, Child child)
{

     Example example = Example.create(parent)
                                 .ignoreCase()
                                 .excludeZeroes()
                                 .excludeProperty("doNotUse")
                                 .enableLike(MatchMode.ANYWHERE);
     session = sessionFactory.openSession();
     
     return session.createCriteria(c).add(example)
                     .createCriteria("children")
                     .add( Example.create( child) )
                     .list();
... sessionFactory.session.close();
}


Error: hibernate error:org.hibernate.QueryException: could not resolve property: children of: com....Parent

Question: The error makes sense, but how can I add criteria to the query so that for example I'm able to list all parents that have a child with the name x, and so on for all of the other parent properties.
I read the documentation but I'm still confused as to how to reference the children.

Please advice.

_________________
EliC


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 10:47 pm 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
i'm having a simliar issue using the Example class, can anyone offer any adivce here? this seems like an excellent way to query, but i can't find many examples using collections of child objects.

please advise.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 9:59 pm 
Newbie

Joined: Mon Jan 23, 2006 11:08 am
Posts: 5
We had the same issue on one to many relations.


Top
 Profile  
 
 Post subject: It works for one-to-many associations
PostPosted: Tue Mar 14, 2006 12:15 pm 
Newbie

Joined: Mon Jan 23, 2006 11:08 am
Posts: 5
We did QBE on one-to-many relationships through sub criteria query, like this,

Criteria subCriteria = providerCriteria.createCriteria("providerNames", JoinFragment.INNER_JOIN);
Disjunction disjunction = Expression.disjunction(); // "or"
Iterator itr = exampleProvider.getProviderNames().iterator();
while(itr.hasNext())
{
disjunction.add(Example.create((ProviderName)itr.next()).ignoreCase().excludeNone());
}
subCriteria.add(disjunction);

To make it work, we have to make sure the @hibernate.key defined inside @hibernate.set is nullable!!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.