-->
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: Substitute mapping with annotations for dynamic entities
PostPosted: Tue Jul 29, 2008 7:48 am 
Newbie

Joined: Thu Dec 13, 2007 5:28 am
Posts: 2
Hi!

After searching for two days without success I finally decided to post this topic.
I want to substitute the following mapping that uses dynamic entities (entity-name) with annotations.

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-access="field">
   <class name="pojo.Person">
      <id name="id" type="long">
         <generator class="native"/>
      </id>

      <property name="name"/>

      <bag name="alive" cascade="all-delete-orphan">
         <key column="person_id" not-null="true" update="false"/>
         <one-to-many entity-name="Alive"/>
      </bag>
   </class>
   
   <class name="util.BBTemporalWrapper" entity-name="Alive">
      <id name="id" type="long">
         <generator class="native"/>
      </id>
      
      <property name="value" type="boolean"/>

      <property name="validityInterval" type="org.joda.time.contrib.hibernate.PersistentInterval">
         <column name="validityStart"/>
         <column name="validityEnd"/>
      </property>

      <property name="recordInterval" type="org.joda.time.contrib.hibernate.PersistentInterval">
         <column name="recordStart"/>
         <column name="recordEnd"/>
      </property>
   </class>
</hibernate-mapping>


Person:
Code:
public class Person {

   private Long id;
   private String name;
   private Collection<BBTemporalWrapper<Boolean>> alive = new LinkedList<BBTemporalWrapper<Boolean>>();

   public Person() {
   }

   public WrappedBitemporalProperty<Boolean> getAlive() {
      return new WrappedBitemporalProperty<Boolean>(alive);
   }

   public Long getId() {
      return id;
   }

   public String getName() {
      return name;
   }
}


BBTemporalWrapper:
Code:
public class BBTemporalWrapper<V> {

   private Long id;
   private V value;
   private Interval validityInterval;
   private Interval recordInterval;
        ...
}


The Alive-Entity is not needed as a class.

Can someone give me a hint, how to use the BBTemporalWrapper-Class as an entity that is used for different tables by using annotations?

Thanks
Fabian


Last edited by eeh_hunt on Wed Jul 30, 2008 3:13 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 3:10 am 
Newbie

Joined: Thu Dec 13, 2007 5:28 am
Posts: 2
Finally we figured it out, the classes look as follows:

Person:
Code:
@Entity
@Table(name = "PERSON")
@SequenceGenerator(name = "SEQ_PERSON_ID", sequenceName = "SEQ_PERSON_ID", initialValue = 1, allocationSize = 1)
public class Person {

   @Id
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_PERSON_ID")
   private Long id;
   
   @Column(name = "name")
   private String name;

   @Embedded
   @CollectionOfElements
   @JoinTable(name = "PERSON_ALIVE", joinColumns = @JoinColumn(name = "ID"))
   @AttributeOverride(name = "element.value", column = @Column(name = "ALIVE"))
   private Collection<BBTemporalWrapper<Boolean>> alive = new LinkedList<BBTemporalWrapper<Boolean>>();

   public Person() {
   }

   public WrappedBitemporalProperty<Boolean> getAlive() {
      return new WrappedBitemporalProperty<Boolean>(alive);
   }

   public Long getId() {
      return id;
   }

   public String getName() {
      return name;
   }
}


BBTemporalWrapper:
Code:
@Embeddable
public class BBTemporalWrapper<V> {

   private Long id;

   @Column
   private V value;

   @Type(type = "org.joda.time.contrib.hibernate.PersistentInterval")
   @Columns(columns = { @Column(name = "validityStart"), @Column(name = "validityEnd") })
   private Interval validityInterval;

   @Type(type = "org.joda.time.contrib.hibernate.PersistentInterval")
   @Columns(columns = { @Column(name = "recordStart"), @Column(name = "recordEnd") })
   private Interval recordInterval;
   ...
}


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.