AutoCommit with JPA?

1,602 views
Skip to first unread message

C.D.

unread,
Sep 15, 2011, 6:19:37 PM9/15/11
to play-framework
Hi,

It looks like the JPA plugin is doing a commit at the end of a request
and a rollback if that request fails.

Is it possible to switch to autocommits, i.e. every db update commits
immediately without waiting for the request to end?

Thanks.

C.D.

unread,
Sep 15, 2011, 6:21:15 PM9/15/11
to play-framework
BTW, calling JPA.em().flush() does not initiate a commit as well.

Ronald Haring

unread,
Sep 16, 2011, 3:25:58 AM9/16/11
to play-fr...@googlegroups.com
You can do it manually using:
JPA.em().getTransaction().commit()

Regards
Ronald

C.D.

unread,
Sep 16, 2011, 4:01:10 PM9/16/11
to play-framework
getTransaction().commit() forces a commit, yes, but the problem with
that approach is that you can't do any DB operation after that.
Basically, if you do something like:

user.setName("A");
user.save();
JPA.em().getTransaction().commit()
.....
user.setName("B");
user.save();

Last save will give you: "TransactionRequiredException occured : no
transaction is in progress " error.

Basically, I want something like jdbc's auto commit, where every txn
is reflected back to the db, when needed.

Thanks.

Yashaswi Kumar

unread,
Sep 8, 2013, 10:10:53 AM9/8/13
to play-fr...@googlegroups.com
Did you find any solution for immediate commit ??

You Wang

unread,
Sep 8, 2013, 10:00:28 PM9/8/13
to play-fr...@googlegroups.com
I asked this question also, no idea why no one give the solution. I wrote a JPAUtil to help to do the manual transaction at play2 java. you can refer this link:
Reply all
Reply to author
Forward
0 new messages