-->
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.  [ 9 posts ] 
Author Message
 Post subject: Multiple Tables per Entity with Annotations ('entity-name')?
PostPosted: Tue Nov 11, 2008 9:16 am 
Newbie

Joined: Tue Nov 11, 2008 8:15 am
Posts: 2
Location: Europe, Germany, Somewhere
Hello all,

this question references to Hibernate-Core 3.2.6.ga and Hibernate-Annotations 3.3.1.GA.
As stated in Java Persistence with Hibernate, chapter 3.4.1 p.147 et sqq., one can map a class several times using the entity-name tag.

I wonder if this somehow could be done using Hibernate-Annotations.

The goal my team mates and I want to reach is the following:

We're working on an application that connects to a legacy DB2 with a highly normalized table structure that must not be changed. We use the javax annotation @Table(name="VW98578") pointing to our tables.

So we created annotated entity classes using Hibernate tools reverse engineering and integrated everything using Spring 2.5. This works all fine :-)

But every table has two (!) mirror tables. One is for saving an historic record whenever an update or delete has occurred.
The other one is for storing temporary changes that remain temporary as long as the user doesn't explicitly submits her/his changes.

During the time the user works with the temporary table, the domain object is programmatically "locked". I.e. in a lookup table the entity's id is linked to the user's id.

My approach would now be to write Hibernate Interceptors, one for the historic data persistence, the other one to route the user's changes to the temporary views.

As we speak of of 100+ tables, I hesitate repeating the entities for the historical and temporary use.

The Hibernate reference and "Java Persistence (...)" show an intuitive way to reuse an entity class pointing to different tables using <entity-name> (see http://www.hibernate.org/hib_docs/reference/en/html/mapping-entityname.html).

Is there any way to get this configured using Hibernate Annotations? I couldn't find one, but would really appreciate any confirmation.

Or did somebody find a solution for a similar requirement?


Thanks for reading so far and kind regards from Europe, Germany, Berlin,

Karsten


Top
 Profile  
 
 Post subject: Re: Multiple Tables per Entity with Annotations ('entity-nam
PostPosted: Mon Dec 15, 2008 10:47 am 
Newbie

Joined: Mon Dec 15, 2008 10:22 am
Posts: 1
Hello,
I have the same need and i dont find how to do this with Hibernate Annotations. If someone have a solution...

Thanks in advance,

Florent


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2009 6:45 pm 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
Hi,

Have the same problem. Need to map a class to two tables (one for loading entities from existing data, another for storing new entities). Would appreciate any advice how to achieve this using JPA.

Regards,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 3:27 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
As far as I know this can only be done when mapping with xml files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 8:35 am 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
nordborg wrote:
As far as I know this can only be done when mapping with xml files.

Thanks, nordborg
I'm thinking about using em.createNativeQuery() in order to load entities from the "read-only" table.


Top
 Profile  
 
 Post subject: Re: Multiple Tables per Entity with Annotations ('entity-name')?
PostPosted: Thu Jun 04, 2009 8:24 pm 
Newbie

Joined: Thu Jun 04, 2009 8:19 pm
Posts: 1
I just ran into this same problem. I want to keep huge tables of events that happen on my website and have a new table each month in the same schema. Then I'll delete previous month's tables when i need to recover disk space.

I guess i could extend the base Event class once for each month (Event200901,Event200902, etc... ) , but I'd rather just tell the session what table name to use programaticly.

Did anyone find a solution besides switching to XML config files?

Thanks!

Matt


Top
 Profile  
 
 Post subject: Re: Multiple Tables per Entity with Annotations ('entity-name')?
PostPosted: Sun May 02, 2010 9:16 pm 
Newbie

Joined: Sun May 02, 2010 9:09 pm
Posts: 1
I ran into this thread in the forum in order to solve a similar problem. I have a Entity(Foo) table and a EntityHistory(FooHistory) table which gets loaded via some triggers.
I already have Foo mapped as a POJO, but now I also need to get FooHistory to work.

I plan to do the following....refactor and Push up to a new superclass

@MappedSuperclass
public abstract class AbstractFoo{
}

@Entity
public class Foo extends AbstractFoo {
}

@Entity
public class FooHistory extends AbstractFoo {
}


Top
 Profile  
 
 Post subject: Re: Multiple Tables per Entity with Annotations ('entity-name')?
PostPosted: Fri May 21, 2010 2:44 pm 
Newbie

Joined: Fri May 21, 2010 10:11 am
Posts: 1
The solution you suggest works when one wants to work with 2 entities (Foo and FooHistory), however, the entity-name mechanism allows 2 mapping files to map 2 tables to ONE entity.

The rest of the code should not need to know which type of entity it is or if it does then there should be a field isArchived.

I am surprised that there is no annotation equivalent to entity-name.


Top
 Profile  
 
 Post subject: Re: Multiple Tables per Entity with Annotations ('entity-name')?
PostPosted: Sat May 25, 2013 9:16 pm 
Newbie

Joined: Sat Mar 02, 2013 10:37 pm
Posts: 2
Any updates since that time? Because i have directly same requirements.


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