Assuming the following construct of classes:
A Filereader
that finds the matching importer for a file and calls the Importer.import
method.
This method calls the abstract method importSpecific
that is annotated with REQUIRES_NEW.
From the perspective of the container a local call does not open a new Transaction but from the inheritance perspective, i'm not sure.
Does the importSpecific
call in ImporterBase.import
create a new transaction or not and why is it like this?
Class FileReader:
@Singleton(name = "FileReader")
public class FileReader extends Traceable {
/*@Inject
@Any
public Instance<Importer> importers;*/
@EJB
ExampleImporter importer;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void listenToFileAvailableEvent(@Observes FileAvailable event) throws InterruptedException {
for (final String filename : event.getFilenames()) {
readFile(filename);
}
}
public void readFile(String filenameWithPath) {
//[...]-> Extract FileMetadata and find correct importer
importer.import(dateiMeta);
}
}
Interface Importer:
@Local
public interface Importer {
void import(FileMetaData dateiMeta) throws Exception;
void importSpecific(FileMetaData dateiMeta) throws Exception;
}
Class ImporterBase:
public abstract class ImporterBase implements Importer {
@Resource
private SessionContext ctx;
@Override
public void import(FileMetaData dateiMeta) throws Exception {
try {
ctx.getBusinessObject(Importer.class).importSpecific(dateiMeta);//This causes the error
} catch (Exception ex) {
//[...] Log Error
throw ex;
}
}
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public abstract void importSpecific(FileMetaData dateiMeta) throws Exception;
}
Class ExampleImporter:
@Stateless
public class ExampleImporter extends ImporterBase {
@Override
public void importSpecific(FileMetaData dateiMeta) throws Exception {
//Import from file
}
}