-->
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: on insert: generate id in a different table
PostPosted: Tue Jun 01, 2004 11:58 am 
Newbie

Joined: Tue Jun 01, 2004 11:33 am
Posts: 1
i'm trying to achieve the following behaviour with hibernate (2.1.3) and a
mysql database (4.x): several tables should share some kind of an unique
identifier, (called "uniqueid" for example) which can be used as refernce to
any kind of data in any table.

the mapping:

Code:
<class name="User" table="user">
   <id name="uid" column="uid" type="long" unsaved-value="-1">
      <generator class="native"/>
   </id>

   <property ... >
      
   <many-to-one name="uniqueID" class="UniqueObject" column="uniqueid" not-null="true" unique="true"/>
</class>

---

<class name="Blah" table="blah">
   <id name="blahid" column="blahid" type="long" unsaved-value="-1">
      <generator class="native"/>
   </id>
   
   <property ... >
   
   <many-to-one name="uniqueID" class="UniqueObject" column="uniqueid" not-null="true" unique="true"/>
</class>

---

   <class name="UniqueObject" table="uniqueobject">
      <id name="uniqueid" column="uniqueid" type="string" unsaved-value="null">
         <generator class="uuid.hex"/>
      </id>
   </class>


i'll have another table called "log" which holds the uniqueid as primarykey
and a timestamp as a data column, therefore i can insert a row into the
"log"-table for every row in the "users" table and another one for every
row in the "blah" table. (i haven't figured out the hibernate mapping for
the "log" table but thats not my primary concern).

the only thing missing is the automatic generation of an entry in the table
"UniqueObject" every time i insert a "user" object.

can hibernate provide such a behaviour or do i have to alter my classes
to insert the row manually.

thanks in advance
art


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 5:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
cascade="save"

_________________
Emmanuel


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.