How JPA Transactions Work ? DAOs and Transactions generic is possible ?

Hi all,

I have a question respect to a EJB3.0 JPA Transactions work.

if i have the folowing code inside EJB container:

In a Generic DAO:

public Object mergeEntity(Object entity) {

return em.merge(entity);

}

public Object persistEntity(Object entity) {

em.persist(entity);

return entity;

}

In a Facade:

public void execute(){

obj.persistEntity(entity);

obj.mergeEntity(entity);

}

When transaction is committed ?

When execute method finish ?

Another question for transactions is.

If a have a factory of DAOs one for EJBs and other for DAOs implemented with JDBC hard code.

What implement a generic layer for manager transactions transparently for my Facades ?

if assumes, i manager transactions manually what abstract this layer to my facade use a comon treatment for transactions ?

It's necessary for my application a common ana trasparent DAOs and transaction use for client layer.

Thanks.

[1054 byte] By [Solraca] at [2007-11-27 9:08:13]
# 1

Container-managed transactions can only be started when a business method of a Session bean

or Message-driven bean (e.g. onMessage) is invoked.Any other code that is called from within

such a method runs within the same global transaction context, unless a different EJB invocation

is made, in which case that method's transaction management meta-data applies.

A Java Persistence Entity class is not an EJB component, so such container-managed transaction

demarcation never applies to the methods of the Entity itself.From a global transaction perspective

any interaction with Java Persistence Entities from the session bean / MDB are treated just like any

other utility code that happens to be called from the business method.

If a container-managed transaction is started when the method is called, it will be committed by the

container when the method completes.

ksaksa at 2007-7-12 21:46:01 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
Thanks Ksaks!
Solraca at 2007-7-12 21:46:01 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...