-->
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: createAlias syntex / how it works
PostPosted: Fri Nov 23, 2012 1:06 pm 
Newbie

Joined: Thu Nov 22, 2012 11:50 am
Posts: 3
Imagine the path:

Code:
entity1.entity2.entity3.entity4.entity5.attribute;


That means that entity1 has an object entity2.
Entity2 has an object entity3
(so on...)
entity5 has attribute "attribute".

I want to create an criteria to search for that "attribute" on "entity5". How should my criteria be:

Code:
    criteria.createAlias("entity2.entity3","entity2.entity3");
    criteria.createAlias("entity2.entity3.entity4","entity2.entity3.entity4");
    criteria.createAlias("entity2.entity3.entity4.entity5","entity2.entity3.entity4.entity5");
    criteria.add( Restrictions.like("entity2.entity3.entity4.entity5.attribute","mySearchString") );


or this only this works? :
Code:
    criteria.createAlias("entity2.entity3.entity4.entity5","entity2.entity3.entity4.entity5");
    criteria.add( Restrictions.like("entity2.entity3.entity4.entity5.attribute","mySearchString") );


PS: can I create an alias for the root entity?
Code:
    criteria.createAlias("entity1","entity1");
    //all other createAlias


I´m asking this, because I´m trying to create a generic filter using Criteria.
Thanks all!


Top
 Profile  
 
 Post subject: Re: createAlias syntex / how it works
PostPosted: Fri Nov 23, 2012 2:08 pm 
Newbie

Joined: Fri Nov 23, 2012 12:03 pm
Posts: 4
entity1.entity2.entity3.entity4.entity5.attribute;

In this case i believe that entity1 has a reference of entity2 which intern has a reference of entity3....and entity5 has an attribute.
And You want to fetch value where the constraint is attribute in entity5.
What value you have with you is the entityObject1 and with this you gonna fetch the value.

What you can do here is.

While creating instance of your helper class, say like Query is your helper class. so


Query query2 - new Query(entity2.class);
query.addCriteria("query1", entity1Object);

Query query3 - new Query(entity3.class);
query.addCriteria(query2);

Query query4 - new Query(entity4.class);
query.addCriteria(query2);

Query query5 - new Query(entity5.class);
query5.addCriteria(query4);
query5.addCriteria("attribute", attribute);

Now pass this query5 to the hibernate using :

getDefaultDao().findUsing(query5)

Hope this will help you.


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.