Skip to main content

Why the entity did not be persistted to dababase

1 reply [Last post]
Anonymous

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@cn.fujitsu.com
--------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cf126330
Offline
Joined: 2005-03-29

Persistence.createEntityManagerFactory is the bootstrap method intended to be used in Java SE environment.

In Java EE environment, emf can be obtained via injection or lookup, and since it's provided by the container, it can be associated with container transaction.

-cheng