-->
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: Map two tables to same java class using annotations
PostPosted: Wed Sep 21, 2011 7:42 am 
Newbie

Joined: Wed Sep 21, 2011 6:47 am
Posts: 1
I have the following code in a mapping file. Mapping files are to be replaced by annotations.
So in order to convert it to annotation i need to be able to Map the same Employee class to two tables employee and employeeHistory. Both the tables employee and employeeHistory have exactly the same schema.

org.hibernate.Session object's save(String, Object) was being used to save an Employee object to one of the two tables employee or employeeHistory based on a property. The String was the entity-name attribute from the hbm file. It should not be affected.

I have shown only minimal code from the hbm file
Code:
<hibernate-mapping>
   <class entity-name="employee" name="com.esolutions.demo.Employee"
      table="employee">
      <id name="id" type="java.lang.String">
         <column name="id" />
         <generator class="assigned" />
      </id>
      <property generated="never" lazy="false" name="name"
         type="java.lang.String">
         <column name="name" />
      </property>
   </class>
   <class entity-name="employeeHistory" name="com.esolutions.demo.Employee"
      table="employeeHistory">
      <id name="id" type="java.lang.String">
         <column name="id" />
         <generator class="assigned" />
      </id>
      <property generated="never" lazy="false" name="name"
         type="java.lang.String">
         <column name="name" />
      </property>
   </class>
</hibernate-mapping>


How can I do it using annotations. I am using hibernate core version 3.6.7
Any help is appreciated.


Top
 Profile  
 
 Post subject: Re: Map two tables to same java class using annotations
PostPosted: Wed Sep 21, 2011 9:49 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It is not supported with annotations: http://docs.jboss.org/hibernate/core/3. ... entityname


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.