I am using following code to add an entity to datastore. However, I am getting an exception which I am not able to resolve. Any insights?
EntityManager em = EMFService.get().createEntityManager();
MyEntity temp = new MyEntity (param1, numOptions, option1, option2, option3);
em.persist(temp);
em.close();
I get the following exception at em.close() line in above code:
javax.persistence.PersistenceException: Cannot make object transient since object is new and not yet committed
at org.datanucleus.api.jpa.NucleusJPAHelper.getJPAExceptionForNucleusException(NucleusJPAHelper.java:302)
at org.datanucleus.api.jpa.JPAEntityManager.close(JPAEntityManager.java:197)
at com.vikrams.examquestweb.dao.Dao.addQuestion(Dao.java:34)
It's weird that searching for the exception description "Cannot make object transient since object is new and not yet committed" in Google gives no matching results. Am I the first one who got this. Maybe I am making some really silly mistake somewhere. Please help.