Hibernate实体类定义总结

1:类头部
@Entity
@Table(name = "tb_user")


2:主键
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;


联合主键
@Table(name = "tb_msgtarget", uniqueConstraints = { @UniqueConstraint(columnNames = { "msgbody_id", "registration_id" }) })


3:String类型字段
@Column(name = "registration_ids", nullable = false, length = 128)
private String registrationIds;


4:int类型字段
@Column(name = "msg_type", nullable = true, columnDefinition="int(1) default 0 COMMENT '通知方式'")
private int msgType;


5:Blob大字段
@Column(name = "file_content", nullable = true, columnDefinition="Blob(16000000)")
private byte[] fileContent;


6:非持久化字段
如果一个属性并非数据库表的字段映射,就务必将其标示为@Transient,
否则,ORM框架默认其注解为@Basic
@Transient
private String url_img;


7:外键关联
@ManyToOne  
@JoinColumn(name="device_id", referencedColumnName="registration_id")  
 private Device device; 
默认情况下,关联的实体的主键一般是用来做外键的。但如果此时不想主键作为外键,则需要设置referencedColumnName属性

你可能感兴趣的:(Hibernate)