我正在尝试向名为MSTRAuthorizations的表中插入一行。当这样做时,我得到一个错误,说不能执行JDBC批处理更新。该行不在数据库中-所以-我看不出它怎么可能更新任何东西。正在使用的数据库是Oracle。在进行插入时,keyid是在Oracle序列的帮助下生成的。我的理解是,在Oracle12c之前,键ID(主键)的自动递增是不可能的。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
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();
}
}
}
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;
}
}
修正了以下内容:hibernate:在涉及外键的复合主键星座中,insertable=false,updatable=false属于哪里?
当数据保存到表中时,在数据库端生成ID。只需将ID和时间戳的“insertable”和“updatable”设置为false即可。
我试图使用Hibernate用Java映射Oracle数据库,但我面临一个问题。代码如下: Java应用程序: Hibernate配置文件: Hibernate场景表映射文件:
我刚刚将Spring MVC(3.2.8)应用程序从Ant迁移到Maven,所以我没有更改代码,只更改了库,因为会自动导入依赖项。从那时起,我有很多DB错误,例如ORA-00932、trnasaction超时...... 或者举个例子: 或这个: DB是: 这里是进口的hibertante罐。。。
我在ubuntu 14.04LTS上使用oracle 11g。我有一个名为成员的表,我由以下sql创建, 后来我更新了这个表格, 现在,当我运行“DESC members”时,它会显示结果, 最后,我运行了这样的插入sql, 它显示了错误, 第1行错误:ORA-00932:数据类型不一致:预期数字为二进制 有人能帮我解决问题吗?而且我也不确定在这个过程中我是否可以添加图像或路径的二进制文件。有人能
当我执行我的查询时,我得到错误:
我将非常感谢对这个例外的帮助。 我对这个错误做了一些研究,但找不到解决方法。我将JPA与hibernate一起使用,并在执行查询时得到这个错误。 显然,关于java LocalDate和oracle Date有一些我不理解的地方。:( 这就是目标: java.sql.SqlSyntaxerRoreXception:ORA-00932:不一致的数据类型:预期的日期已获取二进制 非常感谢提前给你的提示