-->
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: Cascading non foreign key to Child Table
PostPosted: Tue Mar 08, 2011 11:43 am 
Newbie

Joined: Sun Feb 20, 2011 8:55 am
Posts: 6
I have a parent table, t_books_category and a corresponding child table T_Book with a 1-n mapping. My configuration files for the two tables are as under:

Mapping for T_BOOKS table
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="domainObject.Book" schema="super" table="t_books">
      <id name="bookId" column="book_id" type="long">
         <generator class="sequence">
            <param name="sequence">SEQ_ID</param>
         </generator>
      </id>
      <property name="bookName" column="book_name" type="string" />
      <property name="categoryDate" column="cat_date" type="date" />
      <many-to-one name="booksCategory" class="domainObject.Category">
         <column name="cat_id" not-null="true" />
      </many-to-one>
   </class>
</hibernate-mapping>


Mapping for T_BOOKS_CATEGORY
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="domainObject.Category" table="t_books_category"
      schema="super">
      <id name="categoryId" column="cat_id" type="long">
         <generator class="sequence">
            <param name="sequence">seq_id</param>
         </generator>
      </id>
      <property name="categoryName" type="string" column="cat_name" />
      <property name="categoryDate" type="date" column="cat_date" />
      <set name="books" inverse="true" cascade="save-update,delete,delete-orphan">
         <key column="cat_id" />
         <one-to-many class="domainObject.Book" />
      </set>
   </class>
</hibernate-mapping>



As you can see I have been able to map the foreign key attribute of cat_id. However there is one further requirement, there is an additional column cat_Date which is also present in the child table and both values will be the same. However this field is a non key field in both the tables. How do i perform the mapping for this column such that save and update on the master table is cascaded to the child table too.

Thank you and I would appreciate any help.


Top
 Profile  
 
 Post subject: Re: Cascading non foreign key to Child Table
PostPosted: Thu Mar 10, 2011 5:29 am 
Regular
Regular

Joined: Fri Jan 28, 2011 11:44 am
Posts: 117
Hi,

Why do you need the categoryDate to be stored in both the category table and the book table ...
It seems useless to me, you should just remove it from the book table and always access it through the category!


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.