Reputation: 3547
Hi I am using Google App Engine SDK 1.7.3 and JPA for Datanucleus.
I can't update an object that is in the variable t
.
I have written my code as indicated in the accepted answer to this question.
If I use the code:
PersistenceManager persistenceManager=JDOHelper.getPersistenceManager(t);
persistenceManager.refresh(t);
return t;
I get:
java.lang.UnsupportedOperationException: Method not supported with JPA
at org.datanucleus.api.jpa.JPAPersistenceManager.refresh(JPAPersistenceManager.java:693)
at com.appspot.diasporajava.dao.GenericDaoImpl.update(GenericDaoImpl.java:74)
If I use the code:
return this.emf.createEntityManager().merge(t);
Where emf is an EntityManagerFactory.
I get:
javax.persistence.PersistenceException: Object with id "com.appspot.diasporajava.entities.Post@447cc9c9" is managed by a different Object Manager
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:302)
at org.datanucleus.api.jpa.JPAEntityManager.merge(JPAEntityManager.java:576)
at com.appspot.diasporajava.dao.GenericDaoImpl.update(GenericDaoImpl.java:76)
Do I have to keep open my persistence manager all the time?
The ocde I use to create objects is the following:
@Override
@Transactional
public T create(final T t) {
EntityManager em = this.emf.createEntityManager();
em.persist(t);
em.close();
return t;
}
Upvotes: 2
Views: 455
Reputation: 3547
The problem is that I did not close the EntityManager
when I got the object t
the first time.
Upvotes: 2