persistence@glassfish.java.net

EJB 3 trouble

From: Mike Fisher <mikefish1982_at_yahoo.com>
Date: Tue, 1 Apr 2008 08:32:05 -0700 (PDT)

I am new to EJB 3 and I started to work with NetBeans and Glassfish but it seems to be difficult.

CurrentlyI am stuck on a problem and need to see if someone here can help me. Weare trying to copy test data from one database to another in the initprocess for our tests and we keep getting exceptions about an XAtransaction already existing. I am using MySQL and really don't want tochange the drivers though I do need to accomplish this copy. Thefollowing is basically what I am doing.

List<OurObject> sourceList = em1.createQuery(select query here).getResultList();
em2.createNativeQuery(truncate existing data).executeUpdate();
for (....) {
//save data to em2
}

I keep getting an error between the query and the truncate. I have tried to put the following code between the two statements

em1.clear();

another try

em1.clear();
em1.close();

another try

em1.clear();
em1.flush();
em1.close();

Theonly thing that I have gotten to work is if I put the query in anothermethod, call it separately, and clear the em before I return.

Whydo I have to go through these pains and why can't I simply kill thefirst transaction easily before continuning. I have come across asimilar problem further down in the test which I had to resolve in asimilar fashion.

Why it is so difficult to close a transaction?

-=Mike



      ____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com