-->
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: Querying associations
PostPosted: Thu Oct 12, 2006 8:20 am 
Newbie

Joined: Thu Oct 12, 2006 7:39 am
Posts: 4
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. Inverse=true. Many-to-One and One-to-Many is defined. Querying parents works, including childs.

What am I doing wrong?

Stefan


Top
 Profile  
 
 Post subject: Answer
PostPosted: Thu Oct 12, 2006 12:19 pm 
Newbie

Joined: Thu Oct 12, 2006 7:39 am
Posts: 4
Hi

OK, if no one wants to help me, I'll do it myself:

Criteria crit = session.createCriteria(Child.class);
crit.add(Expression.eq("mother", mother));
crit.add(Expression.eq("father", father));
List result = crit.list();

Works very fine.

Thanks me alot.


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.