JPA, scope, and autosave?

Posted by arinte on Stack Overflow See other posts from Stack Overflow or by arinte
Published on 2010-03-15T19:59:36Z Indexed on 2010/03/15 21:19 UTC
Read the original article Hit count: 321

Filed under:

I am using JPA and lets say I do something like this

public class MoRun extends Thread {...
public void run() {
    final EntityManagerFactory emFactory = Persistence.createEntityManagerFactory("pu");
    EntityManager manager = emFactory.createEntityManager();
    manager.setFlushMode(FlushModeType.COMMIT);
    someMethod(manager);
    ...
}


public void someMethod(EntityManager manager){
    Query query = manager.createNamedQuery("byStates");
    List<State> list = query.getResultList(); 
    for (State state : list) {
        if(someTest)
            state.setValue(...)
    }
...
}

So for those objects that pass "someTest" and values are updated are those changes automatically persisted to the db even though there is no transaction and I don't explicitly "manager.save(state)" the object? I ask because it seems like it is and I was wondering if the flush is doing it?

© Stack Overflow or respective owner

Related posts about jpa