Hi!
I quite don't understand why I have to call em.refresh(entitybean) in every funtion of a stateful session bean that trys to modify bean values. Maybe someone can give me a pointer. This is my code (non-important columsn snipped)
Entity(access=AccessType.FIELD) @Table(name="myentity") public class MyEntity implements Serializable { @Id(generate = GeneratorType.AUTO) private Long id; @Column private Boolean seen; // getters and setters ommitted @Override public boolean equals(Object o) { if (o instanceof MyEntity) { MyEntity p = (MyEntity) o; if (p.getId().equals(this.getId())) return true; else return false; } return false; } @Override public int hashCode() { return this.id.hashCode(); } }
@Stateful @Remote @SecurityDomain("other") public class BusinessManagerBean implements BusinessManager, Serializable { @PersistenceContext(unitName="mypersistencecontext") EntityManager em; private MyEntity entity; // part of the remote interface public boolean createNew() { entity = new MyEntity(); entity.setValue(true); em.persist(entity); // the following change will automatically propagated to the database entity.setValue(false); return true; } // public remote interface function public boolean doBusinessLogic() { // em.refresh(entity); // change not propagatec to database unless the above em.refresh() is commented out entity.setValue(true); return true; } }
using an EXTENDED persistence context is a good idea :)