users@glassfish.java.net

Why the entity did not be persistted to dababase

From: Zhang JiHui <zhangjh_at_cn.fujitsu.com>
Date: Tue, 01 Jul 2008 19:05:35 +0900

Hi,

The following code was executed in a statful CMT session bean in
bussiness method:
{{{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("oracle");
EntityManager em = emf.createEntityManager();
Order personSel4 = (Order)em.find(Order.class, 2);
personSel4.setShipmentInfo("testbbb");
em.persist(personSel4);
em.close();
}}}

The data did not be written the database, and "No transaction is
currently active"
was reported when I invoked the em.flush(). In the CMT, the JTA is the
default
transacion. I wonder why "there was no active transaction".

But the data was written to the database when I create the
EntityManagerFactory
by injection:
{{{
@PersistenceUnit
private EntityManagerFactory emf;
}}}

Thanks very much if anyone can explain it.

Thanks,
henrry_china

-- 
--------------------------------------------------
Zhang Jihui
Development Dept.I
Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
8/F., Civil Defense Building, No.189 Guangzhou Road,
Nanjing, 210029, China
Postcode: 210024
TEL:+86+25-86630566-918
FUJITSU INTERNAL:79955-918
FAX:+86+25-83317685
Mail:zhangjh_at_cn.fujitsu.com
--------------------------------------------------