Hibernate中Id的table生成策略

@Entity
@Table(name = "Tbl_Student")
public class Student

{
private int id;

@Id
@TableGenerator(name = "student_gen",table = "XT_XH",pkColumnName = "TYPE",valueColumnName = "XH",
pkColumnValue = "stu",allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "student_gen")
public int getId()
{
return id;
}

.................................................................................................

}

系统中有个表叫"XT_XH",它有两个列TYPE(主键)和XH(值)。

每生成一个Student记录,这个Student的id就从XT_XH表中取。

取TYPE=stu的XH。取过之后,这个XH会加1,等着下次来取。

你可能感兴趣的:(Hibernate)