我正在尝试将一行插入名为Mstrauthorizations的表中。执行此操作时,我收到错误消息无法执行JDBC批量更新。该行不在数据库中 - 所以 - 我看不出它是如何更新任何东西的。正在使用的数据库是Oracle。在执行插入时,将在Oracle序列的帮助下生成keyid。我的理解是,在Oracle 12c之前,密钥ID(主键)的自动递增是不可能的。 Mstrauthorizations.java代码是使用Hibernate生成的。
更新:对Mstrauthorizations.java文件进行了更改,现在收到以下错误: java.sql.BatchUpdateException:ORA-00932:不一致的数据类型:预期NUMBER得到了BINARY 我已经初始化了attribuetes / Mstrauthorizations.java文件中表的字段(因此不会传入空值)但这不起作用。
我怎么能至少看到hibernate命令抱怨的列?我正在尝试插入。为什么要执行更新?
日志信息
1323 [main] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: false
1327 [main] DEBUG org.hibernate.event.def.AbstractSaveEventListener - generated identifier: 0, using strategy: org.hibernate.id.Assigned
1347 [main] DEBUG org.hibernate.transaction.JDBCTransaction - commit
1348 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - processing flush-time cascades
1349 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - dirty checking collections
1350 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
1350 [main] DEBUG org.hibernate.event.def.AbstractFlushingEventListener - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
1351 [main] DEBUG org.hibernate.pretty.Printer - listing entities:
1351 [main] DEBUG org.hibernate.pretty.Printer - com.apostx.tables.Mstrauthorizations{employeeid=0, lastlogints=0, reclockts=2007-09-23 10:10:10.0, authorizationsid=0, memo=no value, logonid=joney@mitchell.com, lastname=Mitchell, firstname=Joney, logonpassword=1234567, archived=0, reclockpid=3434, reclockhost=no host, reclocktype=6, active=0, tenantid=5, worktype=0, reclockid=999999}
1368 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
1373 [main] DEBUG org.hibernate.SQL - insert into ORAAPPS.MSTRAUTHORIZATIONS (ACTIVE, ARCHIVED, EMPLOYEEID, FIRSTNAME, LASTLOGINTS, LASTNAME, LOGONID, LOGONPASSWORD, MEMO, RECLOCKHOST, RECLOCKID, RECLOCKPID, RECLOCKTS, RECLOCKTYPE, TENANTID, WORKTYPE, AUTHORIZATIONSID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
1482 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 1
1496 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
1498 [main] DEBUG org.hibernate.util.JDBCExceptionReporter - Could not execute JDBC batch update [insert into ORAAPPS.MSTRAUTHORIZATIONS (ACTIVE, ARCHIVED, EMPLOYEEID, FIRSTNAME, LASTLOGINTS, LASTNAME, LOGONID, LOGONPASSWORD, MEMO, RECLOCKHOST, RECLOCKID, RECLOCKPID, RECLOCKTS, RECLOCKTYPE, TENANTID, WORKTYPE, AUTHORIZATIONSID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]
java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.apostx.hibernate.soverflow.test.TestStack.main(TestStack.java:32)
1498 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 932, SQLState: 42000
1498 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
1498 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 932, SQLState: 42000
1498 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
1499 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - 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:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.apostx.hibernate.soverflow.test.TestStack.main(TestStack.java:32)
Caused by: java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at com.apostx.hibernate.soverflow.test.TestStack.main(TestStack.java:32)
Caused by: java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10656)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 8 more
TIA
主程序 - 数据库连接测试 - 正常工作
package com.apostx.dbconnection.test;
import java.sql.*;
public class TestDBConnection {
public static void main(String[] args) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@scar:1527:DSV", "ora787", "Huiu7ti" );
Statement statement = con.createStatement();
String sql = "select * from MstrAuthorizations";
ResultSet rs = statement.executeQuery(sql);
while (rs.next()) {
System.out.println("first col " + rs.getInt(1) + " second col " + rs.getString(2));
System.out.println( "login id is " + rs.getString("logonid"));
}
con.close();
}
catch ( Exception e ) {
System.out.println("Database Connection Testing Error : " + e);
e.printStackTrace();
}
}
}
主程序:不工作
package com.apostx.hibernate.test;
import java.math.BigDecimal;
import org.apache.log4j.BasicConfigurator;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.apostx.tables.Mstrauthorizations;
public class AddRecord {
public static void main(String[] args) {
BasicConfigurator.configure();
// create session factory
SessionFactory factory = new Configuration().
configure("hibernate.cfg.xml").
addAnnotatedClass(Mstrauthorizations.class).
buildSessionFactory();
// create session
Session session = factory.getCurrentSession();
try {
// create object
System.out.println("about to start the work ....");
Mstrauthorizations mstr = new Mstrauthorizations();
BigDecimal tenantid=new BigDecimal(5);
mstr.setFirstname("Joney"); mstr.setLastname("Mitchell");
mstr.setTenantid(tenantid);mstr.setLogonid("joney@mitchell.com");
mstr.setLogonpassword("1234567");mstr.setReclockid(new BigDecimal(999999));
mstr.setReclockhost("no host");mstr.setReclockpid(new BigDecimal(3434));
mstr.setReclocktype(new BigDecimal(6));
// start transaction
session.beginTransaction();
// save info
System.out.println("about to save the data ...");
session.save(mstr);
// commit transaction
session.getTransaction().commit();
System.out.println("All Saved ...");
}
catch ( Exception e ) {
System.out.println("error message is " + e.getLocalizedMessage());
}
finally {
factory.close();
}
}
}
Mstrauthorizations.java
package com.apostx.tables;
// Generated Jun 22, 2017 9:30:03 PM by Hibernate Tools 4.0.0
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
* Mstrauthorizations generated by hbm2java
*/
@Entity
@Table(name = "MSTRAUTHORIZATIONS", schema = "ORAAPPS", uniqueConstraints = {
@UniqueConstraint(columnNames = { "TENANTID", "LOGONID" }),
@UniqueConstraint(columnNames = { "TENANTID", "EMPLOYEEID" }) })
public class Mstrauthorizations {
private BigDecimal authorizationsid = new BigDecimal(0);
private BigDecimal tenantid = new BigDecimal(0);
private BigDecimal employeeid = new BigDecimal(0);
private String logonid = new String("no value");
private String logonpassword = new String("no value");
private BigDecimal worktype = new BigDecimal(0);
private BigDecimal lastlogints = new BigDecimal(0);
private String memo = new String("no value");
private String firstname = new String("no value");
private String lastname = new String("no value");
private BigDecimal active = new BigDecimal(0);
private BigDecimal archived = new BigDecimal(0);
private BigDecimal reclocktype = new BigDecimal(0);
private BigDecimal reclockid = new BigDecimal(0);
private String reclockhost = new String("no value");
private BigDecimal reclockpid = new BigDecimal(0);
private Timestamp reclockts = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.0");
public Mstrauthorizations() {
}
public Mstrauthorizations(BigDecimal authorizationsid) {
this.authorizationsid = authorizationsid;
}
public Mstrauthorizations(BigDecimal authorizationsid, BigDecimal tenantid,
BigDecimal employeeid, String logonid, String logonpassword,
BigDecimal worktype, BigDecimal lastlogints, String memo,
String firstname, String lastname, BigDecimal active,
BigDecimal archived, BigDecimal reclocktype, BigDecimal reclockid,
String reclockhost, BigDecimal reclockpid, Timestamp reclockts) {
this.authorizationsid = authorizationsid;
this.tenantid = tenantid;
this.employeeid = employeeid;
this.logonid = logonid;
this.logonpassword = logonpassword;
this.worktype = worktype;
this.lastlogints = lastlogints;
this.memo = memo;
this.firstname = firstname;
this.lastname = lastname;
this.active = active;
this.archived = archived;
this.reclocktype = reclocktype;
this.reclockid = reclockid;
this.reclockhost = reclockhost;
this.reclockpid = reclockpid;
this.reclockts = reclockts;
}
@Id
@Column(name = "AUTHORIZATIONSID", unique = true, nullable = false, precision = 22, scale = 0)
public BigDecimal getAuthorizationsid() {
return this.authorizationsid;
}
public void setAuthorizationsid(BigDecimal authorizationsid) {
this.authorizationsid = authorizationsid;
}
@Column(name = "TENANTID", precision = 22, scale = 0)
public BigDecimal getTenantid() {
return this.tenantid;
}
public void setTenantid(BigDecimal tenantid) {
this.tenantid = tenantid;
}
@Column(name = "EMPLOYEEID", precision = 22, scale = 0)
public BigDecimal getEmployeeid() {
return this.employeeid;
}
public void setEmployeeid(BigDecimal employeeid) {
this.employeeid = employeeid;
}
@Column(name = "LOGONID", length = 60)
public String getLogonid() {
return this.logonid;
}
public void setLogonid(String logonid) {
this.logonid = logonid;
}
@Column(name = "LOGONPASSWORD", length = 40)
public String getLogonpassword() {
return this.logonpassword;
}
public void setLogonpassword(String logonpassword) {
this.logonpassword = logonpassword;
}
@Column(name = "WORKTYPE", precision = 22, scale = 0)
public BigDecimal getWorktype() {
return this.worktype;
}
public void setWorktype(BigDecimal worktype) {
this.worktype = worktype;
}
@Column(name = "LASTLOGINTS", precision = 22, scale = 0)
public BigDecimal getLastlogints() {
return this.lastlogints;
}
public void setLastlogints(BigDecimal lastlogints) {
this.lastlogints = lastlogints;
}
@Column(name = "MEMO", length = 100)
public String getMemo() {
return this.memo;
}
public void setMemo(String memo) {
this.memo = memo;
}
@Column(name = "FIRSTNAME", length = 30)
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
@Column(name = "LASTNAME", length = 30)
public String getLastname() {
return this.lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
@Column(name = "ACTIVE", precision = 22, scale = 0)
public BigDecimal getActive() {
return this.active;
}
public void setActive(BigDecimal active) {
this.active = active;
}
@Column(name = "ARCHIVED", precision = 22, scale = 0)
public BigDecimal getArchived() {
return this.archived;
}
public void setArchived(BigDecimal archived) {
this.archived = archived;
}
@Column(name = "RECLOCKTYPE", precision = 22, scale = 0)
public BigDecimal getReclocktype() {
return this.reclocktype;
}
public void setReclocktype(BigDecimal reclocktype) {
this.reclocktype = reclocktype;
}
@Column(name = "RECLOCKID", precision = 22, scale = 0)
public BigDecimal getReclockid() {
return this.reclockid;
}
public void setReclockid(BigDecimal reclockid) {
this.reclockid = reclockid;
}
@Column(name = "RECLOCKHOST", length = 80)
public String getReclockhost() {
return this.reclockhost;
}
public void setReclockhost(String reclockhost) {
this.reclockhost = reclockhost;
}
@Column(name = "RECLOCKPID", precision = 22, scale = 0)
public BigDecimal getReclockpid() {
return this.reclockpid;
}
public void setReclockpid(BigDecimal reclockpid) {
this.reclockpid = reclockpid;
}
@Column(name = "RECLOCKTS")
public Serializable getReclockts() {
return this.reclockts;
}
public void setReclockts(Timestamp reclockts) {
this.reclockts = reclockts;
}
}
答案 0 :(得分:0)
当数据保存到表格时,在DB端生成ID。只需为ID和时间戳将“可插入”和“可更新”设置为false。