哪个生成的类用于Hibernate Java中的String类型主键?或者是否需要String Class for String type?
当我使用更新时出现错误
org.hibernate.StaleStateException:批量更新意外返回 来自update [0]的行计数;实际行数:0;预期:1
这是我的实体类Book.java
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
//import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
@Table(name="book1")
public class Book {
@Id
@Column(unique=true,length=20)
private String ACC_NO;
private String CALL_NO;
private String AUTHOR;
private String TITLE;
private String IMPRINT;
private String YEAR;
private String EDITION;
private String SUBJECT;
private String SERIES;
private String PAGES;
@DateTimeFormat(pattern="mm/dd/yyyy")
private Date DATE_RELEASE;
private String BOOK_STATUS;
private Byte RESER_STATUS;
public String getACC_NO() {
return ACC_NO;
}
public void setACC_NO(String aCC_NO) {
ACC_NO = aCC_NO;
}
public String getCALL_NO() {
return CALL_NO;
}
public void setCALL_NO(String cALL_NO) {
CALL_NO = cALL_NO;
}
public String getAUTHOR() {
return AUTHOR;
}
public void setAUTHOR(String aUTHOR) {
AUTHOR = aUTHOR;
}
public String getTITLE() {
return TITLE;
}
public void setTITLE(String tITLE) {
TITLE = tITLE;
}
public String getIMPRINT() {
return IMPRINT;
}
public void setIMPRINT(String iMPRINT) {
IMPRINT = iMPRINT;
}
public String getYEAR() {
return YEAR;
}
public void setYEAR(String yEAR) {
YEAR = yEAR;
}
public String getEDITION() {
return EDITION;
}
public void setEDITION(String eDITION) {
EDITION = eDITION;
}
public String getSUBJECT() {
return SUBJECT;
}
public void setSUBJECT(String sUBJECT) {
SUBJECT = sUBJECT;
}
public String getSERIES() {
return SERIES;
}
public void setSERIES(String sERIES) {
SERIES = sERIES;
}
public String getPAGES() {
return PAGES;
}
public void setPAGES(String pAGES) {
PAGES = pAGES;
}
public String getBOOK_STATUS() {
return BOOK_STATUS;
}
public void setBOOK_STATUS(String bOOK_STATUS) {
BOOK_STATUS = bOOK_STATUS;
}
public Byte getRESER_STATUS() {
return RESER_STATUS;
}
public void setRESER_STATUS(Byte rESER_STATUS) {
RESER_STATUS = rESER_STATUS;
}
public Date getDATE_RELEASE() {
return DATE_RELEASE;
}
public void setDATE_RELEASE(Date dATE_RELEASE) {
DATE_RELEASE = dATE_RELEASE;
}
}
**Update command in BookDAOImpl.java is below use for both save and Update**
@Override
@Transactional
public void saveBook(Book Book) {
sessionFactory.getCurrentSession().saveOrUpdate(Book);
}
答案 0 :(得分:1)
对于基于字符串的主键,您有两个选择:
Hibernate中的其他生成器主要处理从基于表的IDENTITY
或AUTO_INCREMENT
列获得的数值或者由数据库序列支持提供的SEQUENCE
或者自定义hibernate_sequences
表。