org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update,这个异常怎么处理?

user.hbm.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">
<hibernate-mapping>
<class name="com.bjsxt.hibernate.User">
<id name="id">
<generator class="uuid"/>
</id>
<property name="name"/>
<property name="password"/>

<property name="createTime"/>
<property name="expireTime"/>

</class>
</hibernate-mapping>
hibernate.cfg.xml

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

<hibernate-configuration>
<session-factory >

<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:oracle:thin:@192.168.1.111:1521:myorcl</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.password">tiger</property>
<!-- property name="hibernate.connection.pool_size"></property -->

<!-- dialect for Oracle (any version) -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>

<property name="hibernate.show_sql">true</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="com/bjsxt/hibernate/User.hbm.xml"/>

</session-factory>
</hibernate-configuration>
代码:public class ExportDB {

public static void main(String[] args) {

//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();

SchemaExport export = new SchemaExport(cfg);

export.create(true, true);
}
};
package com.bjsxt.hibernate;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Client {

public static void main(String[] args) {

//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();

//创建SessionFactory
SessionFactory factory = cfg.buildSessionFactory();

Session session = null;
try {
session = factory.openSession();

//开启事务
session.beginTransaction();

User user = new User();
user.setName("张三");
user.setPassword("123");
user.setCreateTime(new Date());
user.setExpireTime(new Date());

//保存数据
session.save(user);

//提交事务
session.getTransaction().commit();
}catch(Exception e) {
e.printStackTrace();
//回滚事务
session.getTransaction().rollback();
}finally {
if (session != null) {
if (session.isOpen()) {
//关闭session
session.close();
}
}
}

}
}

第1个回答  2010-07-18
把你配置文件的
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<mapping resource="com/bjsxt/hibernate/User.hbm.xml"/>

去掉试试,我没Oracle数据库,不能试,但是我觉得,你那样配置了应该是打开JDBC的东西,而在你save时用的是Hibernate的方法,JDBC 不能直接保存实体对象,所以应该会出错。
这也只是猜想,你试试本回答被提问者采纳
第2个回答  2010-08-02
<generator class="sequence">
<param name="sequence">DEPARTMENT_ID_SEQ</param>
</generator>