另一种可能性是使用
@Formula注释从另一个表中获取值。每当您加载实体时,这将自动生成一个子选择。
我认为您需要这样的东西:
@Entitypublic class MainEntity{ @Id private Integer ID; @Column(name="SOMEFIELD") private String SomeField; @Formula("(SELECt ot1.LABEL FROM OtherTable1 ot1 WHERe ot1.CODE = CODE_FK_1)") private String Label1;}[Hibernate docs]
[1]中对此信息很少,因此您可能需要反复试验才能使其正确使用(但您应该可以使用进行解决
hibernate.show_sql=true。)
这种方法有两个缺点:
- 这是特定于hibernate的代码
- 这是纯SQL,因此可能是特定于数据库的
高温超导
[1]:http :
//docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-
hibspec-
propertyhibernate文档



