同一个交易中的这三个步骤,但步骤1始终是成功的。我想知道JPA的交易是否不支持原生查询(" drop table和create table")。提前谢谢你们!!像这样的代码:
try {
tx.begin();
table1 t1 = new table1();
t1.setC1(c1);
t1.setC2(c2);
EntityManager em = emf.createEntityManager();
em.persist(t1);
Query query1= em.createNativeQuery("drop table if exists table2").executeUpdate();
Query query2= em.createNativeQuery("xxxxxxxxxxxxxxxx").executeUpdate();
tx.commit();
rt = true;
} catch (Exception e) {
try {
tx.rollback();
} catch (Exception e1) {
PUB.log(e, PUB.getLineInfo());
}
}
这是声明:
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class MainSessionBean implements MainSessionBeanRemote {
@PersistenceUnit(unitName = "CC2016JPA2")
static EntityManagerFactory emf;
@Resource
UserTransaction tx;