Hibernate version: 3.0
I am building mapping documents against a legacy schema and am running into trouble defining a many-to-one association between two objects that is expressed by a join table, which identifies the first object by its ID as well as its "type."
The association is between an Datasource and its owner, which is a User:
Code:
class Datasource {
int id;
String name;
User owner;
}
class User {
int id;
String username;
}
The problem is that, in addition to Datasources, there are several other objects that are associated with their owners via the same join table but which may have keys in common with Datasources. For this reason the OWNERS table contains three columns: UserID, ObjectID and ObjectType. To obtain the owner of a Datasource, I would execute the following SQL statement:
Code:
SELECT * FROM USERS WHERE ID IN (SELECT UserID FROM OWNERS WHERE ObjectID=<datasourceId> AND ObjectType='TYPE_Datasource')
At this point my owner mapping for a Datasource looks like:
Code:
<join
table="OWNERS"
optional="false">
<key
column="ObjectID"
unique="true"/>
<many-to-one
name="owner"
column="UserID"
class="com.tsunami.rbservice.model.User"
not-null="true"/>
</join>
Does anybody know of a way that I can express the static condition "ObjectType='TYPE_Datasource'" in my mapping?