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

andydale do-not-reply at jboss.com
Fri Sep 22 04:59:59 EDT 2006


Karma,

I found that annotating the class (where the data is persisted) with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)  solved the problem for me, but unfortunately it does not seem to work for you.  But after reading your post i have revisited the problem and removed the annotations and it still works !!! so i really don't know what the cause of problem was in the first place. 

I would imagine that the underlying cause of the problem i had will be the same as the problem you are currently experiencing, namely that the em.persist() only triggers an update and does not wait for the transaction to commit, and i also found that trying em.flush() after had no effect at all.  To see if that is the case turn on full database logging and you should see the insert, select, and then commit in that order.

The current program layout i have that is working is to have a top level method that calls 2 other methods. Method 1 is the presist data method and method 2 is the send message method.  See below:


  | public void action(){
  |      
  |         int pk = 0;
  |         
  |         try{
  |             pk = doPersistData();
  |         }catch(Exception e){
  |             e.printStackTrace();
  |         }
  |         
  |         try{
  |             // send a JMS message
  |             doMessageStuff(pk);
  |         }catch(Exception e){
  |             e.printStackTrace();
  |         }
  |     }

The thread i also create about this on the hibernate website can be found here: http://forum.hibernate.org/viewtopic.php?t=962664&highlight=

Cheers,

Andy

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

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



More information about the jboss-user mailing list