-->
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.  [ 2 posts ] 
Author Message
 Post subject: Set property on join table
PostPosted: Wed Nov 02, 2005 3:32 pm 
Newbie

Joined: Tue Dec 16, 2003 8:34 am
Posts: 15
Hibernate 3.1

Folks,

I have mapped User<->Role, many-to-many, this way:



<hibernate-mapping
>
<class
name="User"
table="USER"
...
<set
name="roles"
table="USER_ROLE"
>
<key column="user_id" />
<many-to-many class="Role" column="role_id"/>
</set>



<hibernate-mapping
>
<class
name="Role"
table="ROLE"
mutable="true"
>
...
<set
name="users"
table="USER_ROLE"
inverse="true"
>
<key column="role_id" />
<many-to-many class="User" column="user_id"/>
</set>


Everything works as advertised. But there are attributes (properties) on the join table USER_ROLE (for legacy reasons). I need to be able to set a couple of these attributes (columns) on the USER_ROLE table each time Hibernate does an implicit insert as a result of my manipulating the many-to-many relationship. The values I need to insert are *constants*. I do not ever need to read these attributes.

Is there some way to do this without having to model the join table (USER_ROLE) as an entity? I prefer the streamlined model of having the join table completely hidden from my java model classes.

Thanks for any pointers.

Joe


Top
 Profile  
 
 Post subject: Use sql-insert and sql-update
PostPosted: Wed Nov 02, 2005 6:01 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Have a look in the docs for the sql-insert and sql-update tags. They will allow you to easily add constant values to your insert and update statements.


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

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.