i have an app with spring and hibernate. When i run the app on my local it works perfectly and saves and updates user. where when i run in my test container there is no error but at the same time it does not save in database.
The only difference when i run on my local is i use oracle.jdbc.pool.OracleDataSource were as on my test box i used tomcat.dbcp.connection pool.
i came to know thru some threads to use @Transactional attribute since spring needs to know that the update or delete is a part of transaction.After adding annotation at the begining of the method i still does not save to database.
Why are you trying to commit in your testing phase.
This is why in-memory databases are commonly uses for test cases.
Joined: May 12, 2008
sorry when i say test i mean when i run the app in my test environment which runs on Tomcat
The other thing is that this incident came up recently our app was working fine, i thought when we wire hibernate thru spring commit should happen automatically and should not be called explicity.
i also tried annotating a method using @Transactional but still the same behaviour
Perhaps on your local data source you have autocommit set to true which is allowing things to commit. This typically would not be what you want as you want to group operations into a transaction not autocommit them. You are probably configuring your declaritive transactions incorrectly in Spring. Are you applying them only to public methods exposed by an interface and accessing them throough the interface? Spring by default uses java interface based proxies for transactions. If you do not adhere to those rules you need to use AspectJ or proxy target classes rather than interfaces. I would read through the Spring documentation on this you can also see if my post here helps you.
Short story long (by default) if there is no interface there is no transaction.
No, that is not what I meant. Have a look at the link I posted above, I gave some examples there. The annotations go on the implementation class, what I mean is that there must be an interface and you should be accessing that class through its interface.
In other words you should see this
That is what I meant by access it through its interface.
Almost every time someone has the problem you are experiencing it is due to transaction issues. If you want to test to see if you really have a transaction try this inside your @Transactional method