Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLServerException: The statement must be run before the generated keys are available

 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I have a java web application and I'm not able to do a SAVE to the database. I'm able to fetch records from DB, but not a save.

The save used to work until I bought a new laptop and imported my database and application to this new computer. I'm using MS Server 2005 (before and after).

Below is the error I got. Does anyone did what's causing it???:


javax.servlet.ServletException: org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not insert: [com.RXCoreApp.datamodel.BusinessServiceCbo]; uncategorized SQLException for SQL [insert into RX.dbo.Business_Service (Service_Id, Business_Id) values (?, ?)]; SQL state [null]; error code [0]; The statement must be run before the generated keys are available.; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: The statement must be run before the generated keys are available.
org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:286)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:196)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)


root cause


Pls HeLP...
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you using auto-increment field in that table. It would be more helpful if you provide some more details about these fields, like what is the type of Service_Id.. etc.

Service_Id, Business_Id (if one of them is auto-increment field then you don't need to define in your insert statement).

hope it helps..
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. I have auto-increment set on the primary key only. Service_Id and Business_Id are foreign keys.

For my insert, I'm not specifying the primary key field in the insert, so this should not be a problem.

This worked to work. I don't know what changed to be causing this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic