Transaction...

G

gbattine

Hi guys,
excuse me if i open another post on the same argument but now i've
cleared my problem,so i think a new discussion can be useful. Thanks
for precedent replies.

I've to use a transaction in my jsf application.
My problem is:
User insert an experiment into db using 6 different web pages, each
page create one or more prepared statements.
I want the inserting in my db tables happens into a transaction.
I've done this.

The first bean creates an arraylist of statements,and each statements
created in the application has putted into arraylist.
At the end a queryManager loads the arraylist from the first bean,
reads it and executes the statements in a transaction.
The question is transaction doesn't work, commit and rollback doens't
work.
For better understanding the problem i've tried to create a prepared
statement directly from query manager and using transaction and it
works!!
Commit and rollback works correctly!
Why if i try to load an arraylist of statements stored in another bean
transaction doesn't work?
I'm crazying, please help me...
Can you say me another method to collect prepared statements and use it
into a transaction?
 
L

Lew

gbattine wrote:
....
The first bean creates an arraylist of statements,and each statements
created in the application has putted into arraylist.

Perhaps you should make a List of some entity object type or value object
type, so that you don't yet incur the overhead of making PreparedStatements.
At the end a queryManager loads the arraylist from the first bean,
reads it and executes the statements in a transaction.
> ...
> Why if i try to load an arraylist of statements stored in another bean
> transaction doesn't work?
> ...
> Can you say me another method to collect prepared statements and use it
> into a transaction?

At transaction time, open the transaction, use a single PreparedStatement
iteratively through the List, use its setParameter() methods inside the loop body.

Using the same PreparedStatement buys you some of the putative efficiency of
preparing statements. YMMV.

If the loop excepts or breaks abnormally, issue a rollback; if the loop
terminates nicely issue a commit.

In finally {} outside the loop, release any loose resources.

- Lew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top