JPA 2.0 将一个类映射到一张表的不同列
我有实体映射到表 TABLE1 列 COLUMN1 和 COLUMN2
我有类 ResViewer
public class ResViewer() {
private boolean flag;
private int property;
...selectors
}
我有实体类
@Entity
@Table(name="TABLE1")
public class Table1() {
@Id
private long id;
private ResViewer res1;
private ResViewer res2;
...selectors
}
如何将类 res1 和 res2 的字段标志映射到列 COLUMN1 和 COLUMN2?
i have Entity mapped to table TABLE1 with columns COLUMN1 and COLUMN2
i have class ResViewer
public class ResViewer() {
private boolean flag;
private int property;
...selectors
}
i have entity class
@Entity
@Table(name="TABLE1")
public class Table1() {
@Id
private long id;
private ResViewer res1;
private ResViewer res2;
...selectors
}
How can i map field flag of classes res1 and res2 to columnds COLUMN1 and COLUMN2?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 ResViewer 需要使用
@Embeddable
,字段 res1 和 res2 必须用@Embedded
以及@AttributeOverrides
,如@Embedded
的 javadoc 中所示。Your ResViewer needs to be annotated with
@Embeddable
, and the fields res1 and res2 must be annotated with@Embedded
, and with@AttributeOverrides
, as demonstrated in the javadoc of@Embedded
.