Hibernate annotation用@SecondaryTable来实现从一个类对应多张表
程序员文章站
2022-04-14 09:15:25
...
上一篇文章中 Hibernate [email protected]共享主键关联,是以共享主键来实现的,
现在我们来 用@SecondaryTable来实现从一个类对应多张表
@Entity
@Table(name = "article")
@SecondaryTable(name="article_data",pkJoinColumns={@PrimaryKeyJoinColumn(name="article_id")})
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Aricle extends IdEntity<Integer> {
/**
*
*/
private static final long serialVersionUID = -8056490229900614401L;
private String title;
private String subTitle;
private Date addTime;
private String content;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubTitle() {
return subTitle;
}
public void setSubTitle(String subTitle) {
this.subTitle = subTitle;
}
@Temporal(TemporalType.TIMESTAMP)
public Date getAddTime() {
return addTime;
}
public void setAddTime(Date addTime) {
this.addTime = addTime;
}
@Column(name="content",table="article_data")
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
重点在这:
@SecondaryTable(name="article_data",pkJoinColumns={@PrimaryKeyJoinColumn(name="article_id")})
@Column(name="content",table="article_data")
但是 发现不能延迟加载了,我分两张表的目的就是为了延迟加载, OHNO
参考:
上一篇: PHP实现点击验证码或看不清会刷新验证码
下一篇: 2020-08-15