简体   繁体   中英

JPA persist flush functions

I have a strange "problem" according these two functions. I have an EJB container, stateless in which i have my functions that make inserts,updates, deletes selects to my Database.

I have my tables in entities and so the above operations use these entities, except some selects.

The problem i am facing is that, until now(AppServer glassfish) i was using only .persist() function and if there was any violation problem (px bigger "string" than the column's length of a table) then my try catch(Exception e) block was catching these problems and i could send a more firenly message/exception to EJB that called the specific function and therefore the webservice which initially called that function.

Now with JBoss i could not catch the same excpetion and the code returned an rollback exception. When i add the .flush() function at the end of each function then i could catch the exception and all be ok.

(Of course in both situation the rollback was working as i want to do) I have read that with persist the data were remaining in cache and the java was deciding when to do the actual actions at database, and when you call flush then you force the cashed actions to complete at the DB right a way.

My question is, why is this happening? I mean what changed from the one appServer to another with the same code and mostly how if i could not catch the exception the final webservice was getting the exception

The answer lies in how each application manages JPA related operations. By definition, JPA in just an API. There are different JPA provider available on the market such as Hibernate, OpenJPA, EclipseLink, ... So depending on the default JPA provider that each application server uses, you could encounter some discrepancies in the way some operations are handled.

FYI: according to JBoss AS 6 documentation, it is absolutely normal that you get a RollbackException as it is thrown when the commit() method fails

JBoss RollbackException documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM