-->
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: Narrow result set by the collection of string object
PostPosted: Tue Jun 26, 2007 11:30 am 
Newbie

Joined: Thu Aug 31, 2006 3:52 am
Posts: 6
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?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 27, 2007 5:48 am 
Newbie

Joined: Thu Aug 31, 2006 3:52 am
Posts: 6
One solution found: use Restrictions.sqlRestriction.

May be another exist...


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.