Michael Strasser
|
Posted: August 03, 2010 04:28 by Michael Strasser
|
|
Here is an interesting one. I am beginning to modernise a Java application and have created a solution to a current requirement that entities can be persisted using database credentials other than those used to define the persistence unit's The ideal solution to the different credentials problem would be for the persistence provider to implement the It works well and calling the EJB that provides the business interface is like this:
Then I tried creating a fluent interface to make the call something like:
It all ran without error and Hibernate dumps all the same SQL statements to the console as before, but nothing was saved into the database! I can only conclude that the transaction was rolled back instead of being committed. Has anybody seen this kind of behaviour before? Did I miss something in the use of fluent interfaces with EJBs? Perhaps this is a peculiarity of the app server or of Hibernate. I ran this on OC4J 10.1.3.4 (a partial Java EE 5 implementation) and Hibernate 3.3. Any thoughts? I have scrapped the fluent interface and restored the original one. |
Attempted fluent interface and uncommited JPA transactions (Hibernate/OC4J)
by: Michael Strasser
Michael Strasser
|
Posted: August 04, 2010 23:20 by Michael Strasser
|
|
Adam Thanks for your feedback. I know OC4J is EOL but our two major customers use it. They will migrate to WebLogic Server during the next 12 months so I am working with that. Fluent InterfaceThe stuff about user credentials was the background to the reason for my original post. There is more detail about that below. I had a servlet that injects a bean, then uses it like this:
It works as expected. But my fluent-interface version of the bean failed to commit the transaction in OC4J. The calling sequence was:
The difference is what happens to the
Have you seen anything like this elsewhere? User credentials and
|
Michael Strasser
|
Posted: August 27, 2010 01:38 by Michael Strasser
|
|
I have finally solved my issue around unexpected results with persistence. It all has to do with threading. I tried all other kinds of ideas but this is the only one that is totally thread-safe. In short, the only solution to what I want to do is to have a class with static, synchronized methods like this one:
Where I even fell into the EJB 101 trap of trying to save state to a stateless session bean! You can get away with it in simple, slow tests but as soon as you try significant load testing you get into trouble. (Hands up if you spotted that error in my previous posts!) Adam, I used a thread-renaming interceptor in my troubleshooting and it really helped to trace where things were going wrong. Thanks! —Michael |
by: Michael Strasser







