db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JimCrowell37 <JimCrow...@EMail.com>
Subject Re: JPA required?
Date Wed, 13 Feb 2013 20:42:06 GMT
José

José Ventura-3 wrote
> 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.

What a great explanation, thanks.

I just looked at my code and I see that I only do the
"conn.setAutoCommit(false)" statement during Database initialization
methods[twice]. I do, however do the "conn.commit()" statement in all the
methods I have written to perform Database operations. I think that all of
these methods only perform one transaction at a time. I'll go back and make
sure that is a true statement.

I think I just felt that the commit was necessary in my Derby operations
code but I do not know why I decided to do the conn.setAutoCommit(false)
operation?

My derby code is somewhat basic and not to complex but I am thankful for
your info in case I need to
write something more interesting someday.

Regards,
Jim...



--
View this message in context: http://apache-database.10148.n7.nabble.com/JPA-required-tp127242p127281.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.

Mime
View raw message