我正在寻找一种方法来一个实体与另一个实体纯粹通过Hibernate关联(没有多余的关系数据库列映射),而不是需要单独的DAO调用。我搜索周围的解决方案,我能找到的唯一的事情就是@Formula
但我无法得到它的工作。试想一下:休眠:虚拟列
@Entity
class CommonEntity {
@MagicAnnotation("maybe with HQL?")
private SuperEntity superEntity;
}
@Entity
class SuperEntity { }
这意味着,有时CommonEntity
是SuperEntity
,我想对POJO本身吸气所以它具有通过简单get()
访问SuperEntity
。有没有干净地做到这一点,这样,当我这样做commonEntityDAO.get(1L);
,其中1L是SuperEntity,则该实体将被设置?
在数据库中的表看起来像:
table common_entity (common_entity_id int primary key, name string);
table super_entity (super_entity_id int primary key, extra_field string, common_entity_id int);
你说CommonEntity是阿SuperEntity但在你的例子CommonEntity有SuperEntity。 – adrianboimvaser 2011-02-09 20:06:57