【问题标题】:initialValue attribute of @TableGenerator shows issue in Hibernate but not in JPA@TableGenerator 的 initialValue 属性在 Hibernate 中显示问题,但在 JPA 中没有
【发布时间】:2013-05-26 00:31:44
【问题描述】:
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 中,当我使用增量策略时,它显示没有问题,但增量问题

请帮助我并提前感谢

【问题讨论】:

  • 请有人给我解决方案
  • 我在 hibernate jira 论坛中提出了同样的问题

标签: java hibernate annotations generator


【解决方案1】:

我也遇到了同样的问题。这是与hibernate老生成器和JPA的不匹配。

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

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

【讨论】:

  • 谢谢。你救了我的一天!对于任何对序列生成器不起作用(例如不尊重初始值集)有问题的人,只需按照 Stephane 所说的去做。
猜你喜欢
  • 2012-10-29
  • 1970-01-01
  • 1970-01-01
  • 2011-05-19
  • 2015-12-31
  • 1970-01-01
  • 2018-07-12
  • 1970-01-01
  • 2015-08-02
相关资源
最近更新 更多