• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic