Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate Annotation for Entity existing in more than 1 catalog

I have a Person entity mapped by Hibernate to a database table in a database catalog "Active". After a period of time, records in this database table in the "Active" catalog are archived/moved to an exact copy of the table in a database Catalog "History". I have the need to retrieve from both the Active and History Catalogs. Is there a better way to model this with Hibernate annotations than making an abstract class that 2 classes extend from.

This is what I have now.

@MappedSuperclass
public abstract class Person  {

    @Id
    private Integer id;
    private String name;
}

@Entity
@Table(name="Person", catalog="Active")
public class PersonActive extends Person {
}

@Entity
@Table(name="Person", catalog="History")
public class PersonHistory extends Person {
}
like image 741
Daniel Spivey Avatar asked Mar 04 '10 16:03

Daniel Spivey


1 Answers

To my knowledge, that would be the right way to do it with annotations (you kinda have two tables so you need two entities). Then run a polymorphic query on the Person entity. I find this pretty clean by the way.

PS: Can you add a pointer on how to do this with mapping files, I'm really curious.

like image 99
Pascal Thivent Avatar answered Oct 09 '22 11:10

Pascal Thivent