小编典典

@TableGenerator的initialValue属性在Hibernate中显示问题,但在JPA中未显示

hibernate

package com.sb.firstjpaexample.pojo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

  @Entity
  @Table(name = "EMPLOYEE")
  public class Employee {

@Id
@TableGenerator(name = "TABLE_GEN", table = "SEQUENCE_TABLE", pkColumnName = "SEQ_NAME", valueColumnName = "SEQ_COUNT", pkColumnValue = "EMP_SEQ", initialValue = 1001, allocationSize = 5)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "TABLE_GEN")
private int employeeId;

@Column
private String employeeName;
@Column
private String designation;
@Column
private double salary;

public int getEmployeeId() {
    return employeeId;
}

public void setEmployeeId(int employeeId) {
    this.employeeId = employeeId;
}

public String getEmployeeName() {
    return employeeName;
}

public void setEmployeeName(String employeeName) {
    this.employeeName = employeeName;
}

public String getDesignation() {
    return designation;
}

public void setDesignation(String designation) {
    this.designation = designation;
}

public double getSalary() {
    return salary;
}

public void setSalary(double salary) {
    this.salary = salary;
}

}

“此POJO在JPA中将初始值为1001,在Hibernate中为1作为初始值”还有一个疑问,如何在此处使用注释设置增量步长在JPA中,当我使用增量策略时,它没有问题,但是增量问题

请帮助我,在此先感谢


阅读 396

收藏
2020-06-20

共1个答案

小编典典

我只是有同样的问题。它与hibernate的旧生成器和JPA不匹配。

您需要将此添加到您的配置中

请参阅hibernate文档:http
:
//docs.jboss.org/hibernate/annotations/3.5/reference/en/html/ch01.html#d0e200

2020-06-20