-->
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: one-to-many relation and multiple conditions
PostPosted: Thu Apr 03, 2014 11:14 am 
Newbie

Joined: Thu Apr 03, 2014 11:11 am
Posts: 1
Hi,

I have 2 tables:
1. a master table with single attributes of some objects (id, name, title, ...)
2. a table with repeating attributes (master_id, attribute_name, attribute_value)

Example data for #2:
- 10, "authors", "John Bill"
- 10, "authors", "Merry J"
- 10, "owners", "Chris O."
- 11. "authors", "Andrew K."

It's a one-to-many relation:
<set name="repeating" table="xxx" cascade="none" mutable="false" lazy="true" fetch="join">
<key column="...."/>
<one-to-many class="...." />
</set>

I want to find the master object (id=10) where
"authors" = "John Bill" and "authors" = "Merry J" and "owners" = "Chris O."

For the first condition i can do it in that way:

session.createCriteria(Master.class)
.createCriteria("repeating")
.add(Restrictions.eq("attributeName", "authors"))
.add(Restrictions.eq("attributeValue", "John Bill"))
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();

How can i add other conditions?

Thanks


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.