db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Ventura <st.ne...@gmail.com>
Subject Re: JPA required?
Date Wed, 13 Feb 2013 19:56:15 GMT
By default, connections start in Auto-Commit mode, which means every
statement is executed as a single transaction.
http://docs.oracle.com/javase/tutorial/jdbc/basics/transactions.html#disable_auto_commit

To group several statements in a transaction, you first set autoCommit to
false (just like your example); then, execute all the statements you want;
and then execute *conn.commit()* (or *conn.rollback()* if you detect an
error). Since you said everything is working, I assume there is a call to
conn.commit() somewhere in your code.

If the call to commit() is being made "too soon", such as after each
statement (kind of what happens with autoCommit on), and the host goes down
between statements, you have to worry about consistency yourself. Consider
a program that withdraws money from one bank account, commits, then
deposits into another account, then commits: if the host goes down between
commits, some money just disappeared.

On the other hand, if the call to commit() is being made "too late" (only
when the user quits the program, for example), then if the host goes down
before that, none of the new data will be in the database. It will still be
consistent, but data will have been lost.

What you need to do is find out what statements (if any) should be grouped
in atomic blocks for your application, then commit() each time one of those
blocks finish.


On Wed, Feb 13, 2013 at 5:28 PM, JimCrowell37 <JimCrowell@email.com> wrote:

> Bergquist, Brett-2 wrote
> > For your use case, probably not.   JPA is not something that is going to
> > solve a database element corruption and in fact with JPA and its normal
> > use, you have less control when entity changes are flushed to the
> > database.
> >
> > Note that if you don't have your database stored on medium that has write
> > caching, if the host computer goes down, the database is not going to be
> > corrupt; it might not have the latest change, but it will be consistent
> if
> > you are using transactions.
>
> Brett...
> My Derby Database is hosted on my HDD in a /db folder under the Java
> Application folder...
>
> >" ... if you are using transactions."
> The above phrase made me look at my code to see if I am using transactions.
> I wrote the derby software some time ago and I have the following lines of
> code but I
> do not understand why I did the "conn.setAutoCommit(false)" statement...
>
>             //  Control transactions manually...
>             //  NOTE:   Auto commit is on by default in JDBC...
>             conn.setAutoCommit(false);
>
> Everything is working fine but I wanted to assure myself that the above
> operation is OK.
>
> Many Thanks,
> Jim...
>
>
>
>
>
> --
> View this message in context:
> http://apache-database.10148.n7.nabble.com/JPA-required-tp127242p127277.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
>

Mime
View raw message