PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : javax/EJB TransactionAttribute Annotation wirksam an nicht-interface Methode?


Sephiroth
2012-01-09, 19:11:58
Hi,

kann ich eine TransactionAttribute wirksam an eine Methode einer Java Session Bean anbringen, die nicht Teil des Interfaces ist?

Beispiel

import javax.ejb.Remote;

@Remote
public interface Cart {
void invoke();
}


import javax.ejb.Local;

@Local
public interface CartLocal {
void invoke();
}


import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;

@Stateless
public class CartBean implements Cart,CartLocal {
@PersistenceContext
private MyPersistence persistence;

@Override
public void invoke() {
List<String> strings = persistence.getList();
for (String str : strings) {
processItem(str);
}
}

@TransactionAttribute(REQUIRES_NEW)
private void processItem(String item) {
// do something here
}
}


Jedes mal wenn processItem() aufgerufen wird, soll nun eine neue Transaktion gestartet werden. Geht das so oder muss processItem() übers Interface bekannt gemacht werden? Laut API-Doku (http://docs.oracle.com/javaee/6/api/javax/ejb/TransactionAttribute.html) müsste es gehen aber ich bin mir nicht sicher.

The annotation can be specified on the bean class and/or it can be specified on methods of the class that are methods of the business interface or no-interface view.