-->
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: How to work with tables with same table schema?
PostPosted: Wed Nov 07, 2007 9:45 pm 
Newbie

Joined: Wed Jan 31, 2007 9:55 pm
Posts: 16
I have two tables, orders and orders_history with same table schema. Therefore, how should I create the value objects and hibernate mapping files for them actually?

As far as I understand, I should have to create TWO separate Java VO (with same fields on java class), e.g. order and orderHistory with hibernate mapping files like:

<hibernate-mapping default-lazy="false">
<class
name="com.test.vo.OrderVO"
table="ORDERS"
>
>

<hibernate-mapping default-lazy="false">
<class
name="com.test.vo.OrderHistoryVO"
table="ORDERS_HISTORY"
>
>


Then, if I have to copy the data from Orders table to OrderHistoryVO table
1. get collection of OrdersVO from Orders table (e.g. from OrdersVO)
2. loop them and then
- create OrdersHistoryVO
- set individual fields by get corresponding fields from OrdersVO
- can't use simple Object cast as two different type of objects
- quite troublesome

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 2:58 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
This sounds more like something for a database trigger calling a stored procedure than something you want to do in Java code.

If you want to retrieve the orderhistory records you will need some code for that indeed, probably a new VO as well.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 3:39 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
In addition to what the previous poster wrote I think you can construct more or less arbitrarry sql and tell hibernate to stuff the result in an object of your liking.

So at least for read access it might be possible to read from the history table and put the result in your normal VO.

But if you really want to you can still map one class to multiple tables.

See "5.3. Mapping a class more than once" in the reference documentation

J.S.


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.