-->
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: Join a value type with criteria
PostPosted: Tue Dec 27, 2005 11:05 am 
Newbie

Joined: Tue Dec 27, 2005 10:39 am
Posts: 9
Hi,

I wanted to extend an application which has JDBC DAOs and make it support hibernate DAOs (for caching purpose, lazy loading,etc.) . I 'd prefer not to modify my domain model and my persistence schema.
I am a hibernate newbie so my question below might appear weird.

Actually I would like to use a <join> in my mapping file for a value type (activeState) with a selection criteria.

I have two tables:

create table if not exists jobs (
id int not null,
description varchar(100),
owner varchar(20) not null,
status tinyint(1) not null default 0,
primary key(id)
)

create table if not exists jobstates (
jobid int not null,
state varchar(10) not null,
statedate timestamp DEFAULT CURRENT_TIMESTAMP,
isactive tinyint(1) not null default 0,
primary key(jobid,state)
);

jobstates.jobid is a foreign key to job.id primary key.
The state column of the jobstates is used to persist the state (Running, Queued, Stopped, Ended) of the Job and isactive is a flag to determine which in which state the Job is. There's a line for each state of the Job.

I also have a Job class. This job class has an activeState property (which is a Java 5 Enum) which should hold the current state of the Job.

I thought of a value type mapping like:

<class name="Job" table="jobs">
...
<join table="jobstates">
<key column="jobid"/>
<property name="activeState" column="state" />
</join>

The problem is that I would like to get only the jobstates.state property where isactive column is set to 1. The <join> mapping element does not provide a formula attribute where I could restrict the jobstates to a single line. The problem is not about creating a custom UserType for a Java5 enum but about a "weird" mapping for a value type that I would like to achieve.


How could I do this ?

Thanks in advance,
bengalister


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 1:34 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
You can use a subselect in join for this.


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.