您的位置:首页 > 数据库 > Oracle

oracle 实现自动增长

2008-06-06 13:59 423 查看
数据库设计:

在oracle 创建表 :

create table test (in int ,loginname varchar(128),loginpass varchar(128));

alter table test add constraint primary key(id);

在oracle 创建sequence:

create sequence seq_id
minvalue 1
start with 1
increment by 1
cache 20;

java代码:

pojo类:

package com.pojo;

/**
* Test generated by MyEclipse - Hibernate Tools
*/

public class Test implements java.io.Serializable {
// Fields

private long id;
private String name;
private String pass;


// Constructors

/** default constructor */
public Test() {
}


/** minimal constructor */
public Test(long id) {
this.id = id;
}

/** full constructor */
public Test(long id, String name, String pass) {
this.id = id;
this.name = name;
this.pass = pass;
}



// Property accessors


public long getId() {
return this.id;
}

public void setId(long id) {
this.id = id;
}


public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}


public String getPass() {
return this.pass;
}

public void setPass(String pass) {
this.pass = pass;
}


xml映射文件:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="com.pojo.Test" table="TEST" schema="WTL">
<id name="id" type="long">
<column name="ID" precision="22" scale="0" />
<generator class="sequence">
<param name="sequence">seq_id</param>----------关键代码
</generator>


</id>
<property name="name" type="string">
<column name="NAME" length="128" />
</property>
<property name="pass" type="string">
<column name="PASS" length="128" />
</property>
</class>
</hibernate-mapping>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: