class decalaration:
@Stateless
@Local( { IMyLocalSLSB.class })
@Remote( { IMyRemoteSLSB.class }) })
public class mySLSB implements IMySLSB {
private EntityManager em;
and now some methods for inserting/updating and deleting db records are transactions annotations required, I thought they were not as jboss and EJB3.0 handle them using defaults:
public void crud(MyEntity myEntity) {
em.merge(myEntity);// inserts or updates
}
public void deleteInsert(MyEntity myEntity) {
MyEntity found = em.find(MyEntity.class, myEntity.getMyEntityPK());
if (found == null) {
em.merge(myEntity);
} else {
em.remove(found);
}
}
And finally, is this the best way to return a record/entity but not persist any further changes. I take a record and alter the data and then display (I could put into a DTO but this seems neater/less objects)
public MyEntity getAnEntity(integer id){
MyEntity myEntity = em.find(MyEntity.class, id);
org.hibernate.Session session = (Session) em.getDelegate();
session.evict(myEntity);
return myEntity;
}
To summarizes are annotation requried on methods for transactions in an slsb, and is session.evict the best way to stop any changes being persisted ?
Thanks!