Problem with persistence
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 persis开发者_运维百科tence.xml
to Hibernate
doesn't help.
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
精彩评论