1、创建序列
class="sql">-- Create sequence
create sequence DEMO_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
2、Java实体对象配置
package com.boonya.demo.business.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
@Entity
@Table(name="demo")
public class Demo implements Serializable
{
private static final long serialVersionUID = -6933265249358475103L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator="demo_emp_seq")
@SequenceGenerator(name="demo_emp_seq", sequenceName="DEMO_SEQ")
@Column(name="ID",columnDefinition = "int(11)", nullable = false)
private int id; // 编号
@Column(name="NAME",columnDefinition = "nvarchar2(30)", nullable = false)
private String name; // 名称
@Column(name="NOTE",columnDefinition = "varchar2(100)", nullable = true)
private String note; // 备注
@Transient
private String tempField; // 临时字段
public Demo()
{
}
public Demo(String name,String note)
{
this.name=name;
this.note=note;
}
public Demo(int id,String name,String note)
{
this.id=id;
this.name=name;
this.note=note;
}
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 String getNote()
{
return note;
}
public void setNote(String note)
{
this.note = note;
}
public String getTempField()
{
return tempField;
}
public void setTempField(String tempField)
{
this.tempField = tempField;
}
}
注:必须实现可序列化接口。