on 2007 Jul 25 9:38 AM
I don't get Application-Managed Entity Managers to work from servlet code. Does anyone know what I am doing wrong or if this is a bug? (NW7.1 SR1)
The following servlet code which uses a container managed EM works fine:
// @PersistenceUnit
// private EntityManagerFactory emf;
@PersistenceContext
public EntityManager em;
@Resource
UserTransaction utx;
protected void doPost(...) throws ServletException {
//EntityManager em = emf.createEntityManager();
Part p = new Part();
p.setDescription("description");
p.setName("firstPartName");
p.setId(3L);
utx.begin();
em.persist(p);
utx.commit();
while very similar code using application managed code does not work. It does not throw any exception, but simply does not persist anything to DB...
@PersistenceUnit
private EntityManagerFactory emf;
// @PersistenceContext
// public EntityManager em;
@Resource
UserTransaction utx;
protected void doPost(...) throws ServletException {
EntityManager em = emf.createEntityManager();
Part p = new Part();
p.setDescription("description");
p.setName("firstPartName");
p.setId(3L);
utx.begin();
em.persist(p);
utx.commit();
em.close();
Request clarification before answering.
Thanks for the answers! Works like a charm now Points awarded...
Message was edited by:
Clemens Fehr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 18 | |
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.