spring_150908_hibernate_id_sequence
1、新建java工程:spring_150908_hibernate_id_sequence,添加相关jar包(spring、hibernate、ibatis)如下图所示:
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.SequenceGenerator; import javax.persistence.Table; @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.SEQUENCE,generator="s_gen") @SequenceGenerator(name="s_gen",sequenceName="s_seq",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; } }
3、新建以下类和配置文件:
这些类和配置文件在之前的spring_hibernate的里实现的!