Why do I need to use a transaction to persist an Entity? Is there something I can add to my persistence.xml to auto-commit?
This doesn’t insert:
em.persist(this);
But this does:
em.getTransaction().begin();
em.persist(this);
em.getTransaction().commit();
I guess my initial reference point was this GWT doco
public void persist()
{
EntityManager em = entityManager();
try
{
em.persist(this);
}
finally
{
em.close();
}
}
JPA does not define such behaviour; any “persist()” is defined to wait til the next transaction according to the spec. Obviously some implementations of JPA (such as DataNucleus JPA) do provide that (auto-commit) facility, but it’s beyond (not part of) the JPA spec