-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate stored Procedures in MSSQL Identity <sql_insert>
PostPosted: Fri Mar 11, 2011 11:52 am 
Newbie

Joined: Fri Mar 11, 2011 11:33 am
Posts: 1
I tried to execute insert stored procedure for table and hibernate mapping file with Identity generator field.

<hibernate-mapping>
<class name="...Tabletest" table="Test" schema="dbo" catalog="TestData">
<id name="id" type="int">
<column name="ID" />
<generator class="identity" />
</id>
<property name="Test" type="string">
<column name="Test" />
</property>
<sql-insert callable="true" check ="none">{call dbo.insert_Test (@data=?)}</sql-insert>
</class>
</hibernate-mapping>

Unfortunately hibernate does not handle identity with stored procedures well. My guess it is because it is trying to retrieve new identify data, executes “select SCOPE_IDENTITY() AS GENERATED_KEYS” statement which is getting out of scope from stored procedure execution. What is the best practice to implement simple key generator using MSSQL server and stored procedures in hibenate? Do i have to use uid keys or composite keys?

Exception with identity field:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [Tabletest]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
….
com.microsoft.sqlserver.jdbc.SQLServerException: A result set was generated for update.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:171)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:403)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)


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

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.