Re: JPA + Postgres = autocommit?

Поиск
Список
Период
Сортировка
От Davygora, Yuriy
Тема Re: JPA + Postgres = autocommit?
Дата
Msg-id B204CB55F9D32D41A9A5413EA3F13F8C3BEC700F@email.sulzer.de
обсуждение исходный текст
Ответ на Re: JPA + Postgres = autocommit?  (Dave Cramer <pg@fastcrypt.com>)
Ответы Re: JPA + Postgres = autocommit?
Список pgsql-jdbc

 

  Hello,

 

  thank you all for your replies.

 

  I did quite a lot of digging in the source code or the postgres jdbc-driver and eclipselink and found out the following:

 

1.       In PgConnection.java, the autocommit is initially set to true in the declaration (private boolean autocommit = true). In the constructor of the PgConnection class, several options are checked (PGProperty), but there is none that has to do with autocommit. Thus, unless, the client explicitely calls setAutoCommit(false), it will remain true.

2.       Eclipselink calls the setAutoCommit method of a connection to turn it off and on, but only in the case when transactions are managed by Eclipselink itself. We are using a JTA data source and the transactions are managed by the JEE container, i.e. by the Payara server, which apparently never calls the setAutoCommit mehod. So it might actually be a bug in Payara: if Eclipselink manages the autocommit property, so should Payara too, I guess.

3.       In Eclipselink itself there is no option that could be read from the persistence.xml file and cause Connection.setAutoCommit(false).

4.       The connection properties in the Payara domain.xml file are routed via Eclipselink direcly to the Postgres Driver: the above mentioned PGProperty names. As already mentioned, there is no autocommit option there either.

 

  We have decided to patch the Postgres JDBC driver at least for our local testing environment, in order to include an “autocommit” option in the PGProperty and process it in the PgConnection constructor. Later, when we deploy our product to the servers of our client, if we have similar problems, we will contact the corresponding support.

 

Best regards,

Yuriy

 

 

Von: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql.org] Im Auftrag von Dave Cramer
Gesendet: Dienstag, 26. Juli 2016 01:06
An: rob stone <floriparob@gmail.com>
Cc: John R Pierce <pierce@hogranch.com>; List <pgsql-jdbc@postgresql.org>
Betreff: Re: [JDBC] JPA + Postgres = autocommit?

 

 

 

On 25 July 2016 at 18:48, rob stone <floriparob@gmail.com> wrote:


Sulzer GmbH
Geschäftsführende Gesellschafter: Dr. Johann Sulzer, Albert Euba, Thomas Kahabka
Geschäftsführer: Angelika Rudolph, Harald Lothspeich
Sitz und Registergericht: Stuttgart HRB 7608
http://www.sulzer.de

On Mon, 2016-07-25 at 14:53 -0700, John R Pierce wrote:
> On 7/25/2016 2:48 PM, rob stone wrote:
> > I know nothing about Payara, etc. but the "traditional" way of
> > handling
> > this in an application is to:-
> >
> > BEGIN;
> >
> > Do your inserts/updates etc.
> >
> > COMMIT; or if you caught any errors during the inserting/updating,
> > then
> >
> > ROLLBACK;
>
> Not in Java/JDBC applications.   Rather,  they have the concept of 
> autocommit on/off, you configure it on a per connection basis.    
> commit() and rollback() are API calls to the java database
> connection 
> object.
>

True, however issuing a BEGIN turns autocommit off.

 

Please don't do that in JDBC. This will not have the results you expect. The driver needs to know if it is in autocommit mode or not


Yes. I'd experiment with <property name="AutoCommit" value="false" />
or maybe value="off" and see if it makes a difference.

 

 

Yes

 

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Davygora, Yuriy"
Дата:
Сообщение: Re: JPA + Postgres = autocommit?
Следующее
От: Pavel Raiskup
Дата:
Сообщение: Re: postgresql-jdbc 9.4-1209 src tarball issue