@TableGenerator 的 initialValue 属性在 Hibernate 中显示问题,但在 JPA 中没有 [英] initialValue attribute of @TableGenerator shows issue in Hibernate but not in JPA

查看:24
本文介绍了@TableGenerator 的 initialValue 属性在 Hibernate 中显示问题,但在 JPA 中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 中,当我使用增量策略时,它显示没有问题,但显示增量问题

"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

请帮助我并提前致谢

推荐答案

我刚刚遇到了同样的问题.与hibernate old generator和JPA不匹配.

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

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

这篇关于@TableGenerator 的 initialValue 属性在 Hibernate 中显示问题,但在 JPA 中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆