DBMS: Microsoft SQL Server 2000
DBCP: Apache's
There is a problem when the generated ID is fetched. When Hibernate asks for the second questions resultset, jTDS cannot find it. The insert succeds. Ive tried the code manually, and it works fine. I have no clue why it wont work in hibernate.
The question:
Code:
insert into units (lot_number, serial, art_nr, part_of, unit_state) values (?, ?, ?, ?, ?); select SCOPE_IDENTITY()
The stacktrace:
Code:
java.sql.SQLException: Was expecting a result set
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeQuery(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:179)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:508)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:432)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:906)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:839)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:757)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:720)
at se.novaseptic.novaq.units.UnitModelController.setupUnits(UnitModelController.java:142)
The Hibernate code:
Code:
503 //use one statement to insert the row and get the generated id
504 PreparedStatement insertSelect = session.getBatcher().prepareStatement(insertSelectSQL);
505 try {
506 dehydrate(null, fields, notNull, insertSelect, session);
507 if (!insertSelect.execute()) {
507 insertSelect.getMoreResults();
509 }
510 return getGeneratedIdentity( object, session, insertSelect.getResultSet() );
511 }
However, in the log4j output hibernate is missing a semi colon:
Code:
DEBUG SQL:237 - insert into units (lot_number, serial, art_nr, part_of, unit_state) values (?, ?, ?, ?, ?) select SCOPE_IDENTITY()
Is this misleading information or is this a bug in Hibernate? I haven't had this problem with Postgres before, so I guess this is a problem with MSSQLDriver, but again - I'm just guessing.