日期:2014-05-19  浏览次数:20708 次

hibernate oracle11g 无法创建生成表
数据库版本为 oracle11g
hibernate版本为 hibernate-release-4.1.6.Final
数据库中名为ORCL,创建了一个用户为 hibernate 密码为hibernate 并给了dba权限。

相关文件

User.java
Java code

package com.hibernate;

import java.util.Date;

public class User {
    private String id;
    private String name;
    private String password;
    private Date createDate;
    private Date expireDate;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public Date getCreateDate() {
        return createDate;
    }
    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }
    public Date getExpireDate() {
        return expireDate;
    }
    public void setExpireDate(Date expireDate) {
        this.expireDate = expireDate;
    }    
}





User.hbm.xml
Java code

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >

   <class name="com.hibernate.User" table="t_user">
       <id name="id" column="user_id">
           <generator class="uuid"/>
       </id>
       <property name="name" column="user_name" />
       <property name="password" />
       <property name=""></property>
       <property name="createDate" />
       <property name="expireDate" />
   </class>
</hibernate-mapping>



hibernate.cfg.xml
Java code

<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="hibernate.connection.username">hibernate</property>
        <property name="hibernate.connection.password">hibernate</property>
        <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:ORCL</property>
        <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
        
        <mapping resource="com/hibernate/User.hbm.xml" />
    </session-factory>
</hibernate-configuration>



ExportDb.java
Java code

package com.hibernate;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class ExportDb {

    /**
     * @param args
     */
    public static void main(String[] args) {
    
        //默认读取hibernate.cfg.xml文件
        Configuration cfg=new Configuration().configure();
        
        SchemaExport export=new SchemaExport(cfg);
        
        export.create(true,true);