can you post the full stack trace
Main Topics
Browse All TopicsHello experts,
I have yet another hibernate question, I have an application that works with hibernate + spring MVC + struts. The problem I am having is with, I think, the sessions and detached objects.
When I test the application with one user it works flawlessly, however I have now started some stress testing using JMeter which can simulate as many simultaneous visits as you want, while trying this with 10 simultaneous visits at the time it gives an hibernate error every now and then.
The error given on the page is the following:
javax.servlet.ServletExcep
The stack gives this as error:
object references an unsaved transient instance - save the transient instance before flushing: com.GolfOnline.Beans.Cours
and refers to a very simple query in the GolferTypeDAO which goes wrong:
ArrayList results = (ArrayList)getHibernateTem
(where course is a reference to a 'Course' object retrieved earlier in the same request)
As you can see I use the getHibernateTemplate helper class http://static.springframew
The spring application context holds the SessionFactory and gives this to the available DAO's, where the getHibernateTemplate handles the sessions from.
I've searched the error and found many stories telling about the sessionfactory, sessions, transactions and different patterns (such as the session-per-request, session-per-request-with-d
Firstly I am not exactly sure why it gives me this error, I think it is because in one request I retrieve a 'Course' object and in this same request I use this to retrieve a 'GolferType' object using an association to a 'Course' object. With many simultaneous requests at the same time the first retrieved 'Course' object becomes detached for some reason and can't be used again in a query then?
This is easily solved by using the ID's in the query but It does not feel good as this is more of a workaround instead of actually solving the problem (which probably will come back somewhere else)
Could you advise me on which way to go in order to solve the problem?
All relevant code is below and I will give any addition information if needed.
Thanks in advance,
Max
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yes I am sure of that, a request comes in, the session is started, than immediately the course is retrieved using the ID which is given (and valid) in the request parameters using:
return (Course)getHibernateTempla
The course's reference is saved in the session in a variable which is used from that moment on.
It is checked wether the value is not null and than immediately after that, a function is called with the course object as an argument which does the call that the stacktrace points out as the guilty call eventually ending in:
ArrayList results = (ArrayList)getHibernateTem
causing the error.
The code snipper below displays the tomcat 6 stacktrace, note that this is from a number of simultaneous requests.
Tnx
Sorry it took a while, had to prepare you a proper example and it had to be done inbetween other stuff.
I made the example as simple and small as possible but due to the spring-struts-hibernate combination the project still drags along some MB's from the included libraries.
http://www.maxvandenboom.n
Thanks for looking at it!!
Could you keep this question open a little bit longer so the reference in the re-post of this question will stay valid? Repost of this question:
http://www.experts-exchang
If that one also does not give an answer you might as well delete both at the same time.
Re-post of this question does come with a solution:
http://www.experts-exchang
Business Accounts
Answer for Membership
by: objectsPosted on 2009-03-27 at 20:15:06ID: 24007092
> (where course is a reference to a 'Course' object retrieved earlier in the same request)
are you sure