用户登录
用户注册

分享至

hibernate 主键 注释

  • 作者: 该这么走
  • 来源: 51数据库
  • 2020-10-10
@Column(name="rightid")//对应数据库中的字段
@Id @GeneratedValue(strategy=GenerationType.AUTO)//设置主键,并说明增长方式
private Long id;



  主键用 @id



  这样对整个程序的可读性不好。
建议你改成只有1个id的模式。
即@suppresswarnings("serial")
@entity
@table(name = "tb_index_lefttree", schema = "cendoc")
public class indexcatalog implements java.io.serializable {
??? private catalogid id;
??? public indexcatalog() {
??? }

??? /** full constructor */
??? public indexcatalog(catalogid id) {
??????? this.id = id;
??? }


@embeddedid?? ?
??? @attributeoverrides( {
??????? @attributeoverride(name="sjlsh", column=@column(name="sjlsh", nullable=false, length=64) ),
??????? @attributeoverride(name="yljgdm", column=@column(name="yljgdm", nullable=false, length=22) ),
??????? @attributeoverride(name="ywybzf", column=@column(name="ywybzf", nullable=false,length=16) )???????
??? public catalogid getid() {
??????? return this.id;
??? }
??? public void setid(catalogid id) {
??????? this.id = id;
??? }
}
然后再写一个id类
@embeddable

public class catalogid implements java.io.serializable {

????private string sjlsh;
????private string yljgdm;
????private string ywybzf;

@column(name = "sjlsh", nullable = false, length = 64)
public string getsjlsh() {
?return this.sjlsh;
}

public void setsjlsh(string sjlsh) {
?this.sjlsh = sjlsh;
}

@column(name = "yljgdm", nullable = false, length = 22)
public string getyljgdm() {
?return this.yljgdm;
}
public void setyljgdm(string yljgdm) {
?this.yljgdm = yljgdm;
}

@column(name = "ywybzf", nullable = false, length = 16)
public string getywybzf() {
?return this.ywybzf;
}
public void setywybzf(string ywybzf) {
?this.ywybzf = ywybzf;
}

}



这样整个的阅读性会更好。
软件
前端设计
程序设计
Java相关