users@glassfish.java.net

Stateless beans / JPA - when comit transactions occure?

From: <glassfish_at_javadesktop.org>
Date: Mon, 12 Feb 2007 12:25:42 PST

I have a strange behavious when I try to merge entities with modified values but nothing occures...


This is my scenario:
I have a stateless EJB named 'fooEjb' with one method that updates some entities that looks like:

@Stateless()
public class FooBean implements FooLocal {
  public void updateEntities(Collection<MyEntity> entities) {
    for(MyEntity currEntity : entities) {
      currEntity.setX("value");
      currEntity.setY("value...");
      em.merge(currEntity);
}


And 'Bar' which is is another stateless EJB, with one method that initiate some POJO like:
@EJB(name="fooEjbRef", beanInterface=FooLocal.class)
@Stateless()
public class BarBean implements BarLocal {
  public void start() {
     MyPojo mp = new MyPojo();
     mp.doSomeStuff();
}


I lookup for 'fooEjbRef' in pojo:
public class MyPojo {
  public void doSomeStuff() {
    try {
      InitialContext ic = new InitialContext();
      FooLocal fooLocal = (FooLocal) ic.lookup("java:comp/env/fooEjbRef");
    }
    
    //Load some entities...
    //Prepare a list of entities to remove

   fooLocal.updateEntities(listOfEntitiesToRemove);
}




em.merge is executed per iteration, but nothing is done. UNLESS I add 'em.flush()' at the end of the 'updateEntities()' method in FooBean...


Aint the transaction should be flushed when I end my call to the ejb's method?

I couldn't see anything in log even in FINEST level, the only thing I could have seen is:

[#|2007-02-12T13:36:30.473+0200|FINEST|sun-appserver-ee9.1|oracle.toplink.essentials.session.file:/opt/glassfish/domains/domain1/applications/j2ee-apps/edm/lib/entities.jar-pu1.transaction|_ThreadID=11;_ThreadName=p: thread-pool-1; w: 3;ClassName=null;MethodName=null;_RequestID=ae43984a-1efc-4751-af31-59fa754e093f;|Merge clone with references app.entity.MyEntity_at_c8efc|#]

But nothing else.



Any clue? should I flush the EntityManager when I end my calls? this is really scary and confusing :)


As always, many thanks,

Asaf.
[Message sent by forum member 'trouby' (trouby)]

http://forums.java.net/jive/thread.jspa?messageID=203507