Hibernate annotation用@SecondaryTable来实现从一个类对应多张表

上一篇文章中 Hibernate annotation@OneToOne共享主键关联,是以共享主键来实现的,

现在我们来 用@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

参考:

用@SecondaryTable实现多表联合到一个实体

@SecondaryTable 进行多表映射

 常用 JPA annotation 参考

你可能感兴趣的:(Hibernate,cache,jpa)