Hibernate session.save()实体类,主键增长问题

实体类如下:

package com.wondersgroup.test.entity;
 
import java.io.Serializable;
 
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
 
@Entity
@Table(name = "TB_YYZZ_DIC_Hospital")
public class TbDicHospital implements Serializable{
 
private static final long serialVersionUID = 1L;
private String yyjgbm;
private String byzd;
private String byzd1;
private String byzd2;
private String hysm;
private String hyss;
private String jgjc;
private String jglx;
private int xh;
private String yltbs;
private String yyjgmc;
 
public TbDicHospital() {
}
 
 
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="YYJGBM")
public String getYyjgbm() {
return this.yyjgbm;
}
 
public void setYyjgbm(String yyjgbm) {
this.yyjgbm = yyjgbm;
}
 
 
@Column(name="BYZD")
public String getByzd() {
return this.byzd;
}
 
public void setByzd(String byzd) {
this.byzd = byzd;
}
 
 
@Column(name="BYZD1")
public String getByzd1() {
return this.byzd1;
}
 
public void setByzd1(String byzd1) {
this.byzd1 = byzd1;
}
 
 
@Column(name="BYZD2")
public String getByzd2() {
return this.byzd2;
}
 
public void setByzd2(String byzd2) {
this.byzd2 = byzd2;
}
 
 
@Column(name="HYSM")
public String getHysm() {
return this.hysm;
}
 
public void setHysm(String hysm) {
this.hysm = hysm;
}
 
 
@Column(name="HYSS")
public String getHyss() {
return this.hyss;
}
 
public void setHyss(String hyss) {
this.hyss = hyss;
}
 
 
@Column(name="JGJC")
public String getJgjc() {
return this.jgjc;
}
 
public void setJgjc(String jgjc) {
this.jgjc = jgjc;
}
 
 
@Column(name="JGLX")
public String getJglx() {
return this.jglx;
}
 
public void setJglx(String jglx) {
this.jglx = jglx;
}
 
 
@Column(name="XH")
public int getXh() {
return this.xh;
}
 
public void setXh(int xh) {
this.xh = xh;
}
 
 
@Column(name="YLTBS")
public String getYltbs() {
return this.yltbs;
}
 
public void setYltbs(String yltbs) {
this.yltbs = yltbs;
}
 
 
@Column(name="YYJGMC")
public String getYyjgmc() {
return this.yyjgmc;
}
 
public void setYyjgmc(String yyjgmc) {
this.yyjgmc = yyjgmc;
}
}
dao调用如下:

@Override

public String addHospital(TbDicHospital tbDicHospital) {

 

Session session=null;

Boolean result=false;

System.out.println(tbDicHospital.getYyjgbm());

session=this.sessionFactory.getCurrentSession();

session.beginTransaction();

session.save(tbDicHospital);

session.getTransaction().commit();

session.close();

 

result=true;

 

 

 

return result.toString();

}

 

在执行过程中:存在以下问题:

 

经过排查,传递参数的过程中没有问题:

 

问题出在Hibernate自动生成的SQL语句中,缺少了该字段:

可以发现,并没有yyjgbm字段;

设置字段为@ID的时候,无反应;

是主键增长策略的问题,没法绕开,只好写sql了;

 

 

posted @ 2017-12-22 16:09  大战风车的男人  阅读(1045)  评论(0编辑  收藏  举报