我对Hibernate很新,而执行 tx.commit()我得到了上面提到的异常。我提供了我的POJO类,CFG.XML和 hibernate D A代码,我使用了hibernate 3 jar,并使用Net Beans IDE(7.3)
请仔细检查并让我知道我在哪里犯了错误。
谢谢
public String saveEnrollmentData(String uid, String jsonString) {
String output = null;
try {
factory=new AnnotationConfiguration().configure("com/integra/HibernateTest/hibernate.cfg.xml").addAnnotatedClass(EnrollmentBean.class).buildSessionFactory();
Session session = factory.openSession();
Transaction tx = null;
tx = session.beginTransaction();
EnrollmentBean enrollment = new EnrollmentBean();
enrollment.setUid(uid);
enrollment.setJSONDATA(jsonString);
session.saveOrUpdate(enrollment);
tx.commit();
output="Updated";
}catch(Exception ex)
{
System.out.println("Exception :"+ex.getMessage());
output="Exception :"+ex.getMessage();
}
return output;
}
package com.integra.HibernateTest;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table (name="ENROLLMENT_TEST")
public class EnrollmentBean implements Serializable {
@Id @GeneratedValue
@Column (name="er_id")
private int id;
@Column (name="uid")
private String uid;
@Column (name="JSONData",length=1000)
private String JSONDATA;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getJSONDATA() {
return JSONDATA;
}
public void setJSONDATA(String JSONDATA) {
this.JSONDATA = JSONDATA;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.validator.apply_to_ddl">false</property>
<property name="hibernate.validator.autoregister_listeners">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.10.10.74:1521:imfast</property>
<property name="hibernate.connection.username">cia</property>
<property name="hibernate.connection.password">cia</property>
<property name="hbm2ddl.auto">create</property>
<mapping class="com.integra.HibernateTest.EnrollmentBean"/>
</session-factory>
</hibernate-configuration>
例外: -
9 Jan, 2018 11:37:15 AM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.integra.HibernateTest.EnrollmentDAOImpl.saveEnrollmentData(EnrollmentDAOImpl.java:33)
at com.integra.HibernateTest.EnrollmentServicesImpl.saveEnrollmentData(EnrollmentServicesImpl.java:17)
at com.integra.HibernateTest.EnrollmentAction.saveEnrollmentData(EnrollmentAction.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:269)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.BatchUpdateException: ORA-01747: invalid user.table.column, table.column, or column specification
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10345)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 39 more
Exception :Could not execute JDBC batch update
答案 0 :(得分:1)
根据此页面,名称uid
是保留字
如果您无法更改表格定义, 可以使用它来引用它,例如
@Column (name="`uid`")
我很惊讶您能够使用uid
作为列名创建表格。
答案 1 :(得分:-1)
要更具体地针对此特定错误,您可以点击以下链接以更加清晰。
https://docs.oracle.com/cd/B19306_01/server.102/b14200/ap_keywd.htm
https://www.techonthenet.com/oracle/errors/ora01747.php
此致 拉温德拉