-->
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.  [ 1 post ] 
Author Message
 Post subject: how to use criteria join many object?
PostPosted: Tue Apr 20, 2004 1:44 am 
Regular
Regular

Joined: Wed Dec 03, 2003 9:41 pm
Posts: 87
I find Criteria + Example is a good way to implement most query. But I happen a query and I do not know how to use Example to query.
Class A join B, C, D with many-to-one or one-to-one association. A query codition include sample data of Class A, B, C, D.
I try this way to query
Code:
        Session s = super.currentSession();
        Criteria crit = s.createCriteria(A.class);
        crit.add(Example.create(a));
        if (a.getB() != null) {
            crit = crit.createCriteria("b")
               .add(Example.create(a.getB()));
        }
        if (a.getC() != null) {
            crit = crit.createCriteria("c")
               .add(Example.create(a.getC()));
        }
...

It is ok when createCriteria("b"), but can not continue createCriteria("c").

I also try this:
Code:
        Criteria crit = s.createCriteria(A.class);
        crit.add(Example.create(a));
        crit
            .createAlias("b","b")
            .createAlias("c","c");
        if (searchModel.getB() != null) {
            crit.add(net.sf.hibernate.expression.Expression.eq(
                    "mt.id", searchModel.getMaterial().getId()));
        }
...

But it seems can not use Example to alias object.
Is there a better way?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.