initialValue attribute of @TableGenerator shows issue in Hibernate but not in JPA

柔情痞子 提交于 2019-12-22 18:24:04

问题


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;
}

}

"This POJO takes initial value as 1001 in JPA but takes 1 as initial value in Hibernate" One more doubt how to set increment step here using annotations In JPA it shows no problem but problem in increment when i use increment strategies

Please help me and thanks in advance


回答1:


I just had the same problem. It is the mis-matched with hibernate old generator and JPA.

You need to add this to your config

see hibernate doc : http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/ch01.html#d0e200



来源:https://stackoverflow.com/questions/16836058/initialvalue-attribute-of-tablegenerator-shows-issue-in-hibernate-but-not-in-jp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!