Hibernate version: 3.3.1.GA
Mapping documents: I use annotations
Code between sessionFactory.openSession() and session.close(): I use spring-orm, so i do not manage the sessions directly.
Full stack trace of any exception that occurs: No exceptions at this time
Name and version of the database you are using: hsqldb-1.8.0.10
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hello, I would very much appreciate some pointers on how to query for an object based on a collection-valued property. I have a MappingDO object, which has a collection of RuleDO objects. I would like to create a query that accepts a list of values, finds all the rules that those values satisfy, and returns only those mappings that have all of their rules satisfied. My object classes are at the bottom.
For example:
Mapping1 - has Rule1 and Rule2.
Mapping2 - has Rule2 and Rule3.
if i satsify Rule1 and Rule2, but not Rule3, I would like only Mapping1 to return.
What I am doing now is returning all Mappings that are satisfied by any of their rules, and then checking the other rules programmatically:
List results = template.findByCriteria(DetachedCriteria.forClass( MappingDO.class).createCriteria("rules").add(Restrictions.in("ruleValue", satisfiers)));
I would very much like to do everything in the query, so I was thinking I might need to use the all() expression, but have not been able to figure it out. Any help? Thank you
@Entity
@Table(name = "link_mappings")
public class MappingDO implements Serializable {
private static final long serialVersionUID = -6595917468118497491L;
@Id
@Column(length = 36, name = "link_mapping_id", nullable = false)
private String id;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "mapping")
private Set<RuleDO> rules;
@ManyToOne
@JoinColumn(name = "link_id", nullable = false)
private LinkDO link;
public MappingDO() {
id = UUID.randomUUID().toString();
}
getters/setters ...
}
@Entity
@Table(name = "link_mapping_rules")
public class RuleDO implements Serializable {
private static final long serialVersionUID = -9074503220458650860L;
@Id
@Column(length = 36, name = "link_mapping_rule_id", nullable = false)
private String id;
@Lob
@Column(nullable = false)
private String ruleValue;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private RuleType type;
@ManyToOne
@JoinColumn(name = "link_mapping_id", nullable = false)
private MappingDO mapping;
public RuleDO() {
id = UUID.randomUUID().toString();
}
getters/setters...
}
|