实体类注解生成数据库表

实体基类:是否启用
@MappedSuperclass
public abstract class AbstractBasis extends AbstractEntity
{
	private static final long serialVersionUID = 7952571906802309278L;
	
	/**
	 * 禁用状态,false:禁用  true:可用
	 */
	private Boolean isEnable = true;
	
	@Column(nullable = false)
	public Boolean getIsEnable()
	{
		return isEnable;
	}
	public void setIsEnable(Boolean isEnable)
	{
		this.isEnable = isEnable;
	}
}

@MappedSuperclass 作用:封闭类中的通用属性(如:id),此类不能再添加@Entity或@Table注解,即不会映射到数据库表,产生数据库表,但该类的属性将映射到其子类中,数据库中表也将生成对应的字段。

实体类(标签)

@Entity
@Table(name = "edu_tag")
public class EduTag extends AbstractBasis {
	
	private static final long serialVersionUID = -5409801373006627913L;
	
	private String code;
	private Long appId;
	private Long corpCode;/**教育号编码 */
	private String name;
	private School school;
	
	@Id
	@Column(name="edu_tag_code",nullable = false, length = 20)
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	@Column(name="edu_tag_name",nullable = false,length = 20)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name="edu_tag_appId" ,nullable = false,length = 20)
	public Long getAppId() {
		return appId;
	}
	public void setAppId(Long appId) {
		this.appId = appId;
	}
	@Column(name="edu_tag_corpCode", nullable = false,length = 20)
	public Long getCorpCode() {
		return corpCode;
	}
	public void setCorpCode(Long corpCode) {
		this.corpCode = corpCode;
	}
	     @OneToOne(cascade = CascadeType.REFRESH , fetch = FetchType.EAGER)
	@JoinColumn(name = "edu_corp_shcool")
	public School getShcool() {
		return shcool;
	}
	public void setShcool(School shcool) {
		this.shcool = shcool;
	}
}

@Entity : 实体类
@Table(name  = "xxx"): 定义数据库表名xxx

@Id : 定义主键

@Column: 定时数据库表字段 (name:字段名,nullable:是否允许为null,length:字段长度)

@OneToOne: 定时外键(CascadeType.REFRESH:保持数据完整,查检关联表中的数据,FetchType.EAGER:急加载 )

@JoinColumn: 功能与@Column类似。


org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: could not initialize proxy - no Session (through reference chain: com.nenglong.zsedu.ucenter.api.po.educorp.EduCorp["organization"]->

com.nenglong.zsedu.ucenter.api.po.basic.Organization_$$_jvst2c4_12["name"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException:

 could not initialize proxy - no Session (through reference chain: com.nenglong.zsedu.ucenter.api.po.educorp.EduCorp["organization"]->com.nenglong.zsedu.ucenter.api.po.basic.Organization_$$_jvst2c4_12["name"])

该报错的解决方法: 将FetchType.EAGER.LZAY改为 FetchType.EAGER。



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值