-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate+jTDS not returning id after INSERT
PostPosted: Mon Mar 01, 2004 2:05 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 11:52 am
Posts: 37
Location: Gothenburg, Sweden
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 2:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is fixed in CVS, take a look at http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-724 - to workaround currently use a custom dialect which overrides appendIdentitySelectToInsert to return a null value


Top
 Profile  
 
 Post subject: minor release
PostPosted: Mon Mar 01, 2004 6:57 pm 
Beginner
Beginner

Joined: Wed Oct 29, 2003 11:52 am
Posts: 37
Location: Gothenburg, Sweden
Thanks michael, are there release plans for a minor version where this is fixed as in CVS?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 01, 2004 6:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The next minor release of Hibernate 2.1.x is not scheduled yet.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.