[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: EntityManager not working correctly

andydale do-not-reply at jboss.com
Fri Aug 4 06:32:34 EDT 2006


Hi,

After spending the whole week trying to fix this problem, i am still no closer to the actual solution but i have discovered some more information.  This problem is Postgres specific at the moment as i have tested the EntityManager.find() method call in the same context when using Hypersonic and MySQL and the entity is always found.

After studying the log file created by Postgres (without having the 2 second delay) it seems to not be able to commit the initiial insert statement generated from the EntityManager.persist() call before it tries to query it with the select statement, thus the .find() returns null.  The thing that worries me about this problem is that some times it works with Postgres, and that it always works with the 2 other databases i tested with.  

I have read up on the EntityManager and discovered that it is not thread safe, could this be causing the problem with Postgres, if so i know i need to use an EntityManagerFactory as this is a thread safe object, but how do i just create on factory that the whole of the application can use (be used in different beans, possible JNDI lookup ??), and even then i do not know if this would solve my problem.  Is there anyway of making the EntityManager.persist() method wait until the database has actually commited before it returns ??? I have also tried to introduce flush() calls but they do not solve the problem.

Is this a possible bug in the EntityManager or Postgres JDBC code ???

I also have a very simple test application (.ear file) that just persists some bytes to a database and then tries to find them again in a seperate MDB, and then prints out if it cannot find the persisted object.  If anybody wants it to test the problem  with this application i will make it available to them.


If anyone can help, or offer advice it is appreciated.

Cheers,

Andy



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3963135#3963135

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3963135



More information about the jboss-user mailing list