-->
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: Foreign key generator on property element?
PostPosted: Wed May 14, 2008 4:26 am 
Newbie

Joined: Mon Feb 11, 2008 12:59 pm
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3

Name and version of the database you are using: MySQL 4.1.9

I have the following two tables

user:
Fields include userId BIGINT and standard user type fields

userrole:
Fields include
userRoleId BIGINT Primary (auto increment)
userId BIGINT index
roleId BIGINT index

I want the association of user to userrole to be one to many and use the following association mapping in user mapping file
<list name="roles" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="userId"/>
<list-index column="roleId"/>
<one-to-many class="uk.co.acudev.valueobjects.UserRole" />
</list>

I originally didn't have a userRoleId in userrole (oversight) and before it was added my userrole mapping looked like

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 06-Feb-2008 18:50:58 by Hibernate Tools 3.2.0.CR1 -->
<hibernate-mapping>
<class name="uk.co.acudev.valueobjects.UserRole" table="userrole" catalog="acudevcart">
<id name="userId" type="java.lang.Long">
<column name="userId" />
<generator class="foreign">
<param name="property">user</param>
</generator>
</id>
<version name="version" type="long">
<column name="version" not-null="true" />
</version>
<property name="roleId" type="long">
<column name="roleId" not-null="true" />
</property>
<many-to-one name="role" update="false" insert="false" lazy="false"
column="roleId"
class="uk.co.acudev.valueobjects.Role"
cascade="none"
unique="true"
not-null="false">
</many-to-one>
<many-to-one name="user" insert="false" update="false" not-null="true"
column="userId"
class="uk.co.acudev.valueobjects.User" >
</many-to-one>
</class>
</hibernate-mapping>

i now want to add the userRoleId as an id element instead of userId in the above mapping and therefore userId will become a standard property....

my question: is it still possible to have the userId as a foreign key thats updated with the userId from User when its been saved or do i have to turn cascading off, save user then manually assign its userId to userrole and save userrole ?

it would be nice to have the generator element in any property element.
thanks
adam


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.