Hibernate Annotation for Entity存在于多于一个目录中 [英] Hibernate Annotation for Entity existing in more than 1 catalog

查看:86
本文介绍了Hibernate Annotation for Entity存在于多于一个目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Person实体被Hibernate映射到数据库目录Active中的数据库表中。经过一段时间后,Active目录中此数据库表中的记录将被存档/移动到数据库目录History中的表的完整副本。我需要从Active和历史目录中检索。有没有更好的方法来使用Hibernate注释来建模,而不是创建一个2类扩展的抽象类。

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.

这是我现在拥有的。

@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 {
}


推荐答案

据我所知,这将是正确的做法与注释(你有点儿有两个表,所以你需要两个实体)。然后在 Person 实体上运行多态查询。我发现这样很干净。

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:你可以添加一个指针来指导如何使用映射文件做到这一点,我很好奇。

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

这篇关于Hibernate Annotation for Entity存在于多于一个目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆