File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes SQLServerException: The statement must be run before the generated keys are available Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "SQLServerException: The statement must be run before the generated keys are available" Watch "SQLServerException: The statement must be run before the generated keys are available" New topic
Author

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

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
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

Joined: Dec 06, 2005
Posts: 1321

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..


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQLServerException: The statement must be run before the generated keys are available
 
Similar Threads
learn struts
JCaptcha and Struts
Hibernate insert fails due to generate key failure
Unable to compile class for JSP
IllegalArgumentException : <html:select>