I have problem with using EntityManager.persist(Object)
method. Now when i get rid of other problems, by app work without Exception but object is not put in my data
I was able to fix the same problem by adding the Entity to persistence.xml:
<persistence-unit name="OwnerPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.test.domain.local.Entity</class>
<exclude-unlisted-classes />
</persistence-unit>
</persistence>
Try this:
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
PS: You should set a generation method for your ID as well.
Are you getting a specific exception? It would be helpful to know what it is if you are.
There are a number of similar problems to this already on Stackoverflow:
Spring transactional context doesn't persist data
Spring, Hibernate & JPA: Calling persist on entitymanager does not seem to commit to database
These suggest that you should try adding em.flush()
after the em.persist(chain)
, and altering the @transactional
annotations
You should also check that you have enabled transactional annotations through a line such as :
<tx:annotation-driven transaction-manager="transactionManager"/>
in your .xml configuration