@Entity
@Table(name = "tbl_Student")
public class Student implements Serializable
{
private int id;
private int groupId;
@Id
@TableGenerator(name = "student_gen1", table = "XT_XH", pkColumnName = "TYPE", valueColumnName = "XH", pkColumnValue = "stu1", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "student_gen1")
public int getId()
{
return id;
}
..........................................................................
@Id
@TableGenerator(name = "student_gen2", table = "XT_XH", pkColumnName = "TYPE", valueColumnName = "XH", pkColumnValue = "stu2", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "student_gen2")
public int getGroupId()
{
return groupId;
}
....................................................................
}
详细的id的table生成策略叙述,见
http://blog.youkuaiyun.com/woshixuye/article/details/7278119
本文介绍了一个名为Student的Java实体类,该类使用了@TableGenerator注解定义了两种不同的TableGenerationStrategy来生成主键ID,一种用于生成学生ID,另一种用于生成学生组ID。通过这种方式可以实现更灵活和可控的ID生成机制。
2942

被折叠的 条评论
为什么被折叠?



