l245c4l
l245c4l

Reputation: 4165

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 persistence.xml to Hibernate doesn't help.

Upvotes: 1

Views: 176

Answers (1)

Jim Tough
Jim Tough

Reputation: 15210

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

Upvotes: 1

Related Questions