-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-one association with join table and static condition
PostPosted: Thu May 19, 2005 7:00 pm 
Newbie

Joined: Thu May 19, 2005 6:26 pm
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.