我在Employee表上使用策略= GenerationType.TABLE,我使用@TableGenerator定义了一个生成器(name =" Empl_Gen",table =" ID_GEN",pkColumnName =& #34; GEN_NAME",valueColumnName =" GEN_VALUE")并使用生成器名称"在@GeneratedValue(generator =" Emp_Gen")中指定生成器。 Empl_Gen&#34 ;.当应用程序启动时,它会创建一个名为" ID_GEN"但该表中不包含任何名称的生成器"" Empl_Gen"。实际上它将创建一个生成器" EMPLOYEE"这与我的实体类名相同。也是"" GEN_VALUE"的价值在持久化员工实体时不会增加。员工的ID也是随机生成的。
package com.test.domain;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.TableGenerator;
@Entity
public class Employee {
@TableGenerator(name="Empl_Gen", table="ID_GEN",pkColumnName="GEN_NAME",valueColumnName="GEN_VALUE")
@Id@GeneratedValue(generator="Empl_Gen",strategy=GenerationType.TABLE)
private Long id;
private String Name;
private String Country;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCountry() {
return Country;
}
public void setCountry(String country) {
Country = country;
}
}