Hi guys,
I have a class with association of string objects. Is there any way to narrow the result set by that association with Criteria API?
In reference I see an example with a separate object. It works fine. But I can find the solution with elementary classes :-(
Here is my case:
I have the following structure of DB:
CREATE TABLE DOCUMENT (
ID NUMBER(19,0) NOT NULL,
DESCRIPTION VARCHAR2(255) NOT NULL
);
CREATE TABLE DOCUMENT_REGION (
DOCUMENT_ID NUMBER(19,0) NOT NULL,
REGION_ID VARCHAR2(25) NOT NULL
);
So, DOCUMENT_REGION holds the string values that identify regions.
The following bean represents the model object:
public class Document {
private Long id;
private String description;
private Set regionIds;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set getRegionIds() {
return regionIds;
}
public void setRegionIds(Set regionIds) {
this.regionIds = regionIds;
}
}
So, the regionIds property keeps the set of string objects.
The following mapping is used:
<hibernate-mapping auto-import="false">
<class
name="com.model.Document"
table="DOCUMENT">
<cache usage="read-write"/>
<id
name="id"
column="ID"
type="long">
<generator class="sequence">
<param name="sequence">id_cip_document_sequence</param>
</generator>
</id>
<set name="regionIds" table="DOCUMENT_REGION">
<key column="DOCUMENT_ID"/>
<element type="string" column="REGION_ID" not-null="true"/>
</set>
</class>
</hibernate-mapping>
I need to find all the documents with specified region id. Any thoughts?
|