Hibernate(一) 主键映射
@Id注解可以将实体bean中的摸个属性定义为表示符,该属性可以通过应用自身进行设置,也可通过Hibernate生成(推荐),使用@GeneratedValue注解可以定义该标识的生成策略:
.AUTO
.TABLE
.IDENTITY
.SEQUENCE
?
?
?
@Entitypublic class Student {private BigInteger id;private int age;private String name;@Id//@GeneratedValue(strategy=GenerationType.TABLE,generator = "TB_GEN")@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid")@GenericGenerator(name = "java5_uuid", strategy = "com.woxiaoe.study.hibernate.util.UUIDGenerator")//自定义的生成策略@Column(name = "id", precision = 65, scale = 0)//定义字段长度public BigInteger getId() {return id;}
?
?
?