Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate using mssql

 
naresh kumar gupta kapilavai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai iam developping the stand alone application using hibernate

here iam using the mssql database..

but i got the problem like bellow..


Hibernate: insert into Book (title, author) values (?, ?)
Hibernate: select last_insert_id()
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [my.pack.Book]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:
92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.id.AbstractPostInsertGenerator.getGenerated(AbstractPostInsertGenerator.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:1979
)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2388
)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:37)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:243)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListe
ner.java:269)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:16
7)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener
.java:101)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(Default
SaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEven
tListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateE
ventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.j
ava:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEven
tListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:516)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:506)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:502)
at App1.main(App1.java:19)
Caused by: java.sql.SQLException: [Microsoft][SQLServer JDBC Driver][SQLServer]'last_insert_id' is not a r
ecognized function name.
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.tds.TDSCursorRequest.openCursor(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.execute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeQueryInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.executeQuery(Unknown Source)
at org.hibernate.id.AbstractPostInsertGenerator.getGenerated(AbstractPostInsertGenerator.java:42)
... 16 more


is there any alternative to rectify this ...
any one can u suggest me...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What key generation strategy are you using? Hibernate seems to be trying to get the database to give it an ID (via the function last_insert_id()) and this function doesn't exist. Since last_insert_id() is not an out-the-box function of SQL Server if you are going to use it you will have had to create it yourself.
 
naresh kumar gupta kapilavai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

here iam using generator class="native".i did't understand the problem now also...
can u plz suggest me once again..
iam very new to the hibernate..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. It seems odd that Hibernate is trying to use last_insert_id() with MSSQL - are you using the correct dialect? Using the native generation strategy Hibernate should be trying to use a database specific generation strategy supported by the underlying database. If its is using one that isn't supported then perhaps you have configured it so Hibernate thinks it is using a database other than it is? You could change your generation strategy to something else and Hibernate would stop trying to use this function.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic