gpt4 book ai didi

java - hibernate java中哪个生成的类用于字符串类型主键?或任何需要字符串类型的生成器类

转载 作者:行者123 更新时间:2023-12-01 08:56:15 25 4
gpt4 key购买 nike

Hibernate Java 中哪个生成的类用于字符串类型主键?或者是否需要 String 类型的生成器类?

使用更新时出现错误

org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 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);
}

最佳答案

对于基于字符串的主键,您有两种选择:

  • 使用 UUID 生成器之一将生成的 UUID 存储为字符串。
  • 编写您自己的基于字符串的自定义生成器。

Hibernate 中的其他生成器主要处理从基于表的特定 IDENTITYAUTO_INCRMENT 列或 SEQUENCE 获取的数值由数据库的序列支持或自定义 hibernate_sequences 表提供。

关于java - hibernate java中哪个生成的类用于字符串类型主键?或任何需要字符串类型的生成器类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42017456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com