-->
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: composite-element or many-to-many relations?
PostPosted: Wed Oct 15, 2008 4:17 pm 
Newbie

Joined: Tue Oct 07, 2008 12:17 pm
Posts: 13
Hi,
I've a kind of problem with the relationships between 2 tables.
I would appreciate if someone let me know how to resolve this relationship trap.

Following are the 2 tables called TOKEN which is having token properties and TOKEN_USER which is actually a relationship kind of table with the user.
But USER doesn't represent any separate entity/table. Its a varchar2 field in the TOKEN_USER table and the relations to be mapped are,
1. 'A UserName can be assigned to any number of tokens'.
2. 'A Token can be assigned to any number of UserNames'.
Code:
CREATE TABLE CS_TOKEN (
      CS_TOKEN_ID NUMBER(10 , 0) NOT NULL,
      CS_APPLICATION_ID NUMBER(10 , 0) NOT NULL,
      NAME VARCHAR2(30) NOT NULL,
   );

CREATE TABLE CS_TOKEN_USER (
      CS_TOKEN_ID NUMBER(10 , 0) NOT NULL,
      USERNAME VARCHAR2(30) NOT NULL
   );



I've created two java objects, Token.java represents TOKEN entity and the other is User.java represents TOKEN_USER table. I've created User.java having properties like username, (email, network_id,etc., fields will be populated later from the peoplesoft table view-- ignore these fields as this may confuse ). Only UserName property of User.java has to be mapped with TOKEN_USER table's userName column.

Below is the mapping file for Token table.

Code:
<hibernate-mapping><class name="com.cvc.authenticateUser.cssecurity.hibernate.CsToken" table="CS_TOKEN">
   <id name="csTokenId" column="CS_TOKEN_ID">
            <generator class="increment"/>
        </id>
   <many-to-one name="csApplication" column="CS_APPLICATION_ID"/>
   <property name="name" column="NAME"/>

<bag name="csUsers" lazy="true" table="cs_token_user" order-by="USER_ID asc">
   <key column="CS_TOKEN_ID" />
   <composite-element       class="com.cvc.authenticateUser.cssecurity.hibernate.CsUser">
    <property name="userId" column="USER_ID" not-null="true" />
</composite-element>
</bag>

</class>
</hibernate-mapping>



With the use of <composite-element>, I'm able to get List of users who is assigned to a tokenId.
But I need to fetch all the tokens, who is assigned to a UserName. What kind of relation I can map in this scenario?.

I'm really confused as I don't have a separate USER entity/table which can be possibly mapped with User.java.

Please let me know, do I need to create separate mapping file for TOKEN_USER table and what are the possible relationships can be mapped in this situation.
Sorry for the bit lengthy post.

Thanks in advance,
Velu


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.