利用hibernate给oracle自动创建数据表,出现java.sql.BatchUpdateException: ORA-00903: 表名无效 错误解决如下:
Hibernate.properties配置如下:
## MySQL
## \u6570\u636e\u5e93\u94fe\u63a5
hibernate.dialect org.hibernate.dialect.Oracle9Dialect
hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver
hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl
hibernate.connection.username scott
hibernate.connection.password tiger
user.hbm.xml
<?xml version="1.0" encoding="GB2312"?>
<!DOCTYPE hibernate-mapping SYSTEM "[url]http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd[/url]" >
<hibernate-mapping>
 <class name="org.apple.hibernate.User" table="usertest">
     <!--hibernate为我们生成主键id-->
  <id name = "id" unsaved-value = "null">
   <generator class="uuid.hex"/>
  </id>
  
     <!--默认把类的变量映射为相同名字的表列,当然我们可以修改其映射方式-->
  <property name="name"/>
  <property name="password"/>
 </class>
</hibernate-mapping>
 
测试代码如下:

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
 
class UserTest{
 
 private static SessionFactory sessions;
    public static void main(String[] args) throws Exception{         

     Configuration conf= new Configuration()
   .addClass(User.class);
        

        SchemaExport dbExport=new SchemaExport(conf);
        dbExport.create(true, true);
        sessions = conf.buildSessionFactory();

        
        //start......
        Session s = sessions.openSession();
  Transaction t =  s.beginTransaction();
     System.out.println("start create table ");

     User p1=new User();
     p1.setName("刘俊杰");
     p1.setPassword("12345689�㶫����");
     System.out.println("insert suceess");
     

     s.save(p1);
     t.commit();
     System.out.println("save suceess");
     s.close();
    }
}
这里要注意修改<class name="org.apple.hibernate.User" table="usertest">,要指定表名usertest,oracle默认表名为user,所以必须重新指定表名,不指定则会出现上述错误