简体   繁体   中英

Transaction-type for local postgres tool?

I have a local application (no JEE server) that shall use postgres at the end. I'd like to chose Hibernate as my database framework. I'm now creating the persistence.xml , and wonder which transaction-type I should chose: JTA or RESOURCE_LOCAL, or none?

<persistence-unit name="travelport" transaction-type="JTA">

Further I'd like to use the Hibernate EntityManager in my application. Can I have my application manage the transaction itself somehow (any framework)? Or do I always have to open, commit and close the transactions myself when not using an application server?

You really only need the JTA transaction type if you're running in an EE environment, so definitely choose RESOURCE_LOCAL .

As for transaction management, have a look at Spring Transaction Management - I won't repeat the good examples in that link here, but feel free to post follow-up questions if needs be :-)

And don't forget DB pooling as well ( DBCP , C3P0 etc).

Cheers,

For a SE application, you should use RESOURCE_LOCAL and manage the transaction by yourself.

Automatic transaction management would require the beans/services to have a managed lifecycle and a possibility to plug in into that lifecycle.

I am not aware of a readymade lifecycle framework for Java (Spring is a good option for servlet containers, but be aware of all the goods it brings to the table in addition to the bean lifecycle).

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