日期:2014-05-17 浏览次数:20867 次
<?xml version="1.0" encoding="utf-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="msg" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect"/>
<!-- 建表方式,value值为creat-drop时表示创建应用的时候建表,结束应用的时候表自动删除;
值为update表示如果映射元数据不存在则建立表,如果映射元数据存在并新增加了字段则会添加到数据库表中 -->
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="oracle.jdbc.OracleDriver"/>
<property name="hibernate.connection.username" value="....没错...."/>
<property name="hibernate.connection.password" value=".......没错...."/>
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:orcl"/>
</properties>
</persistence-unit>
</persistence>
package com.demo.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;
@Entity
@Table(name = "User")
public class User implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "ID_sqe")
private int id;
@Column(name = "User_name", length = 20, nullable = true)
private String username;
@Column(name = "User_pwd", length = 40, nullable = true)
private String password;
@Column(name = "User_lev", length = 1, nullable = true)
private int level=0;//0为普通用户,1管理员
public User() {}
public User(int id, String name, String password) {
this.id = id;
this.username = name;
this.password = password;
}
public int getId() {
return id;
}
public void setI