1、新建java工程:spring_150909_hibernate_id_table,如下图所示:
2、建DogPet实体类:
package com.spring.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import javax.persistence.TableGenerator; @Entity @Table(name="t_dog") public class DogPet { private int id; private String name; private int age; private String kind; private String sex; private String health; @Id @GeneratedValue(strategy = GenerationType.TABLE, generator="pk_gen") @TableGenerator(name="pk_gen",table="tb_generator" ,pkColumnName="gen_name" ,valueColumnName="gen_value" ,pkColumnValue="PAYABLEMOENY_PK" ,allocationSize=1) public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getKind() { return kind; } public void setKind(String kind) { this.kind = kind; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getHealth() { return health; } public void setHealth(String health) { this.health = health; } public String toString() { return id+"--"+name+"--"+kind+"--"+age+"--"+health; } }