Yes, I can and did try that. It worked. Thanks..
Now why is it so difficult to do this. Why wouldn't it work by simply using close() or having another method to close the active transaction?
----- Original Message ----
From: Mitesh Meswani <Mitesh.Meswani_at_Sun.COM>
To: persistence_at_glassfish.dev.java.net
Sent: Tuesday, April 1, 2008 2:25:15 PM
Subject: Re: EJB 3 trouble
Can you try following?
em1.getTransaction().begin();
List<OurObject> sourceList = em1.createQuery(select query
here).getResultList();
em1.getTransaction().commit();
em2.getTransaction().begin();
em2.createNativeQuery(truncate existing data).executeUpdate();
for (....) {
//save data to em2
}
em2.getTransaction().commit();
Mike Fisher wrote:
> I am new to EJB 3 and I started to work with NetBeans and Glassfish
> but it seems to be difficult.
>
> Currently I am stuck on a problem and need to see if someone here can
> help me. We are trying to copy test data from one database to another
> in the init process for our tests and we keep getting exceptions about
> an XA transaction already existing. I am using MySQL and really don't
> want to change the drivers though I do need to accomplish this copy.
> The following 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();
>
> The only thing that I have gotten to work is if I put the query in
> another method, call it separately, and clear the em before I return.
>
> Why do I have to go through these pains and why can't I simply kill
> the first transaction easily before continuning. I have come across a
> similar problem further down in the test which I had to resolve in a
> similar 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
> <http://us.rd.yahoo.com/evt=47523/*http://tc.deals.yahoo.com/tc/blockbuster/text5.com>,
> No Cost.
____________________________________________________________________________________
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