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
|