Hi, in my java web apps, I used JBoss, Seam with hibernate,
I used createNativeQuery and SELECT FROM .... to get records from a DB2 table, it works well. I can get all records.
Now, after I got the records, I want to insert some of data to another table, I tried to use createNativeQuery with INSERT INTO statement, something like this:
here, codes get the list or collection from CreateNativeQuery("Select * from table1");
start to loop from the list here.
EntityManager em = emf.createEntityManager();
EntityTransaction tx = null;
tx = em.getTransaction(); //I got runtime error here, it says I can not use getTransaction error,
// start to insert the record something like: createNativeQuery("INSERT INTO ..... table2");
Could you anybody help me how to resolve this problem with some examples? thanks a lot
If an exception rises when you call getTransaction() method on the entity manager, you should check if you are using container manager transaction which is default when @TransactionManagement(TransactionManagementType.BEAN) is not explicitly declared.
To fire native bulk queries, try something like this, extracted from Apress - Pro JPA 2: