views:

14

answers:

1

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!

+1  A: 

To summarizes are annotation required on methods for transactions in an SLSB

No, they are not required. You can apply the @TransactionAttribute annotation at the class-level to specify the default transaction attribute for all business methods of the enterprise bean. If you do not, your bean will default to @TransactionAttribute(REQUIRED) (i.e. all methods are transacted by default).

and is session.evict the best way to stop any changes being persisted?

Pascal Thivent