-->
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.  [ 3 posts ] 
Author Message
 Post subject: Update two/multuple table with single Java Bean
PostPosted: Thu Apr 19, 2007 10:12 am 
Beginner
Beginner

Joined: Thu Apr 19, 2007 9:52 am
Posts: 27
Hi,

I have a requirement, which I am sure is one of its kind but I hope someone has an answer to that.

I have a case where we have multiple identical tables which needs to be associated with single Java Bean. So when I want to create a new record or update the existing record, my call to save or update should update all the three tables.


Any suggestions


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 2:48 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
As far as I know, you cannot map one class to two tables. You will get DuplicateMappingException.

>>> So when I want to create a new record or update the existing record, my call to save or update should update all the three tables.

You can achieve this using database triggers. ( I don't know if your database supports them )

-----------------------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject: Yes it can be done!!
PostPosted: Wed May 23, 2007 5:12 pm 
Beginner
Beginner

Joined: Thu Apr 19, 2007 9:52 am
Posts: 27
Hi Guys,

Just for the reference for everyone I was able to make this thing run. So here is the solution. It runs only on Hibernate3.x

To map the same JavaBean to two different tables you need to specify an entity-name attribute for class like this

Default mapping

<class name="Customer" table="CUSTOMER">
...
</class

Save by calling session.saveOrUpdate(customer);

Duplicate mapping for different table

<class name="Customer" table="HIST_CUSTOMER" entity-name="CustomerHist">
...
</class

Save by calling session.saveOrUpdate("CustomerHist", customer);

I hope it helps somebody

Regards,
Mahen


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.