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: Querying associated objects
PostPosted: Thu Oct 12, 2006 8:07 am 
Newbie

Joined: Thu Oct 12, 2006 7:39 am
Posts: 4
SORRY! Wrong forum...please ignore...

Hi

I have this:

public class Parent {

int id;

Set childs;

public void addImMotherOrf(final Child child) {
getChilds().add(child);
child.setMother(this);
}
public void addImFatherOf(final Child child) {
getChilds().add(child);
child.setFather(this);
}

//plus all the setters and getters
}

public class Child {

int id;

Parent mother;

Parent father;

//plus all the setters and getters
}

Now, I like to query the childs of given parents. I do this like that:

...
Child child = new Child();
Parent mother = new Parent();
Parent father = new Parent();
mother.setId(1);
father.setId(2);
mother.addIamMotherOf(child);
father.addIamFatherOf(child);
Criteria crit = session.createCriteria(Child.class);
crit.add(Example.create(child));
List result = crit.list();
...

This results in the following SQL

select .... from child_table where (1=1)

I checked the mapping. I found it quite correct.

Any suggestions?

Stefan


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.