-->
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: Example.create for son-in-law
PostPosted: Mon Dec 13, 2004 4:37 pm 
Newbie

Joined: Thu Oct 07, 2004 9:20 am
Posts: 11
I am trying to create example criteria for complex objects. I think that the problem boils down to being able to create example criteria for the POJO example of a cat's son/daughter-in-law (the mate of a kitten).

The following approach creates the correct SQL for properties set in the kitten, but ignores all properties set in the son-in-law (it adds AND (1=1) to the where clause).

Code:
Criteria catCriteria = session.createCriteria(Cat.class).add(Example.create(exampleCat));
if (exampleCat.getKittens() != null) {
    for (Iterator iter=exampleCat.getKittens().iterator(); iter.hasNext();) {
        Cat exampleKitten = (Cat) iter.next();
        Criteria kittensCriteria = catCriteria.createCriteria("kittens").add(Example.create(exampleKitten));
        if (exampleKitten.getMate() != null) {
            // the following line has no affect.  No matter what properties
            //I set in the kitten's son-in-law, the hibernate query just adds and (1=1).
            kittensCriteria.createCriteria("mate").add(Example.create(exampleKitten.getMate()));
        }
    }
}
[/i]


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.