EclipseLink with Spring - Can't persist into Db?

Your error is here: @Transactional public void addServer(Server server) { EntityManager em = emf. CreateEntityManager(); emf. CreateEntityManager().

Persist(server); em.close(); } Your are creating two different EntityManager instances, the em, which you are closing, and a new one at the next line with emf. CreateEntityManager() which you are using directly to persist your changes. Try this: @Transactional public void addServer(Server server) { EntityManager em = emf.

CreateEntityManager(); em. Persist(server); em.close(); } I guess that when you close your em instance, your changes are written to the DB, but, in case that they are not, you have to add em.flush(); right before closing the em instance.

Thanks for pointing this out! Actually I think there is another issue with the transaction mechanism, because I have to explicitly begin and commit the transaction to have the data inserted. Following code works fine em.getTransaction().begin(); em.

Persist(server); em.getTransaction().commit(); em.close(); – clem Oct 29 '10 at 7:54.

I am not sure what exactly is wrong with your configuration (I guess EntityManager created manually can't participate in @Transactional transactions), but the typical JPA configuration in Spring looks like this, so you don't need to create EntityManager manually (also note the classname of the factory bean): @PersistenceContext private EntityManager em; @Transactional public void addServer(Server server) { em. Persist(server); }.

– javagirl Jul 13 at 19:11 please could you see this question:link – javagirl Jul 15 at 10:21.

Thx for your answers, both were very helpful. I ended up using LocalContainerEntityManagerFactoryBean, so I could inject the entity manager into my dao. I added servlet-agent-2.5.6.

Jar on the lib folder and and pass VM options : -javaagent:path/to/lib/ervlet-agent-2.5.6. Jar Then I modified ApplicationContext. Xml : And my dao: ... @PersistenceContext private EntityManager em; @Transactional public void addServer(Server server) { em.

Persist(server); } Persistence and transactions work like a charm now!

1 for sharing your final solution – Tomas Narros Nov 2 '10 at 8:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send