It doesn't work when I set "hibernate.jdbc.use_get_generated_keys true" in hibernate.properties.
I download a new MSSQL jdbc driver from microsoft:
http://www.microsoft.com/downloads/details.aspx?FamilyID=9f1874b6-f8e1-4bd6-947c-0fc5bf05bf71&DisplayLang=en
And update SQL Server to sp3a.
Exception:
Code:
java.lang.AbstractMethodError: com.microsoft.jdbc.sqlserver.SQLServerConnection.prepareStatement(Ljava/lang/String;I)Ljava/sql/PreparedStatement;
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:324)
at net.sf.hibernate.util.GetGeneratedKeysHelper.prepareStatement(GetGeneratedKeysHelper.java:39)
at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:246)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:61)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:524)
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 com.dealeasy.ems.monitor.dao.DePurchaseOrderDAO.add(DePurchaseOrderDAO.java:35)
at com.dealeasy.ems.monitor.business.PurchaseOrder.addPO(PurchaseOrder.java:77)
If I set "#hibernate.jdbc.use_get_generated_keys true" , Exception:
Code:
2004-02-25 17:38:50,804(2219) [main] DEBUG net.sf.hibernate.SQL - insert into de_purchase_order (PO_NO, INVOICE_NO, ORDER_DATE, CUSTORMS_DECLARATION_NO) values (?, ?, ?, ?) select SCOPE_IDENTITY()
2004-02-25 17:38:50,804(2219) [main] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
2004-02-25 17:38:51,054(2469) [main] DEBUG net.sf.hibernate.persister.EntityPersister - Dehydrating entity: [com.dealeasy.ems.monitor.table.DePurchaseOrderModel#<null>]
2004-02-25 17:38:51,054(2469) [main] DEBUG net.sf.hibernate.type.StringType - binding '111' to parameter: 1
2004-02-25 17:38:51,101(2516) [main] DEBUG net.sf.hibernate.type.StringType - binding '222' to parameter: 2
2004-02-25 17:38:51,101(2516) [main] DEBUG net.sf.hibernate.type.TimestampType - binding null to parameter: 3
2004-02-25 17:38:51,101(2516) [main] DEBUG net.sf.hibernate.type.StringType - binding null to parameter: 4
2004-02-25 17:38:51,476(2891) [main] DEBUG net.sf.hibernate.impl.BatcherImpl - done closing: 0 open PreparedStatements, 0 open ResultSets
2004-02-25 17:38:51,476(2891) [main] DEBUG net.sf.hibernate.impl.BatcherImpl - closing statement
2004-02-25 17:38:51,492(2907) [main] DEBUG net.sf.hibernate.util.JDBCExceptionReporter - SQL Exception
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot insert the value NULL into column 'id', table 'ems_monitor.dbo.de_purchase_order'; column does not allow nulls. INSERT fails.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRPCRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
Same code is right in Oracle.