I'm using EclipseLink
in my J2SE
project. I'm using mysql
and JPA. I have a simple entity with primary key and String
field. I can read from database using EntityManager#createQuery
but when I try to persist
or merge
entity nothing is put in database and no exception are thrown. I can insert data manually without problems (using same credentials as in persistence.xml
file). Please help! The problem isn't related to jpa implementation I guess because changing provider in persistence.xml
to Hibernate
doesn't help.
views:
24answers:
1
+1
A:
You need to do the persist()
or merge()
inside an active transaction. Then you need to call the commit()
method on the transaction object.
Create a transaction by calling getTransaction()
on the EntityManager
instance, getting back an EntityTransaction object and then calling begin()
on it. Call commit()
on it after your entity updates (such as merge()
) are done.
See: http://download.oracle.com/javaee/6/api/javax/persistence/EntityTransaction.html
Jim Tough
2010-10-14 23:03:34
Accepted answer without upvote doesn't sound right. +1
Pascal Thivent
2010-10-14 23:27:46