-->
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: Join tables - how to map with composite-element
PostPosted: Wed Jan 28, 2009 5:02 am 
Newbie

Joined: Wed Jan 28, 2009 4:29 am
Posts: 1
Hi

We have been successfully using hibernate in our app for several years and it works just great. However, I have a question about mapping files and join tables.

We have a table for USERS and a table for FUNCTIONS. We store the functions available to a user in a APP_FUNCTIONS table. We do this because we have standard extra fields (ROW_VERSION, STATUS, CREATED_BY) that all tables share. We do not physically delete records but set STATUS to 'D' which means that we can't use the USER ID and FUNCTION ID to form the natural primary key.

Across the application, we have tended to create an object to reflect the APP_FUNCTION and have a mapping file which reflects this. This means that our Java object graph also has the join table embedded in it and we also have to maintain the extra mapping file.

So yesterday, I found we could almost achieve what we needed by inserting this to our user mapping file

Code:
<set name="userFunctions" table="USER_FUNCTION">
   <key column="USER_ID" />
   <composite-element class="UserFunction" >

   <many-to-one name="function"
   column="FUNCTION_ID"
   not-null="true"
   class="Function"  lazy="false"/>

   <property name="createdBy" type="java.lang.String" column="CREATED_BY" not-null="true" length="20" />
   <property name="createdTs" type="java.sql.Timestamp" column="CREATED_TS" not-null="true" length="11" />
   <property name="rowStatus" type="java.lang.String" column="ROW_STATUS" not-null="true" length="1" />
   </composite-element>         
</set>


This so very nearly works ! It means that I have a list of userFunctions in my User object and I can get straight from that to my function. It also eliminates the need for that extra mapping file. To me, the composite element looks nearly like an embedded mapping file.

Except that I can't see how to do the following with this construct

1. Make it support an <id> element. I'd like to add new associations from my application and I'd like to point it at our sequence generation implementation when we a new UserFunction to the user.
2. Make it support <version> for when we do updates. We use this across the application. It is fantastic and drives large amounts of very important synchronisation code.
3. Make it support <sql-delete>. As I mentioned, we never physically delete but intercept the deletion with this and simply set the row_status field to 'D'.

Any ideas ? Thanks all.


Chris

Hibernate version:3.2.5

Name and version of the database you are using:Sybase
Code:


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.