0

I have an interface :

public interface LogBookService extends EntityService<LogBookEntity, Long> {
    void writelogNewTransaction(LogBookEntity log);
}

and its implementation :

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class LogBookServiceImpl implements LogBookService {
    @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
    public void writelogNewTransaction(logBookEntity logbook) {
        final List<String> params = new ArrayList<String>();
        new getRepository().merge(entity);
    }
}

and a third service :

@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class GalaxyServiceImpl implements GalaxyService {
    @Resource
    private SessionContext  sessionContext ;
    public void test() {
        for (LogBookEntity log : LogBookEntities) {
            sessionContext.getBusinessObject(LogBookService.class).writelogNewTransaction(log); 
        }
    }
}

When I called a GalaxyServiceImpl via a web service for example, I get this error:

SystemErr R java.lang.IllegalStateException: Requested business interface not found : LogBookService
SystemErr R     at com.ibm.ejs.container.SessionBeanO.getBusinessObject(SessionBeanO.java:677)

can you tell me why please?

Robert
  • 7,394
  • 40
  • 45
  • 64
oumina
  • 31
  • 6

1 Answers1

1

SessionContexts are specific to each bean instance. Since you are doing a dependency injection in the GalaxyServiceImpl bean you are grabbing the SessionContext for that bean, not the LogBookServiceImpl bean. GalaxyServiceImpl doesn't implement LogBookService so that's why it is complaining you can't find that as it's business interface.

Instead, you can either inject the LogBookServiceImpl bean using @EJB or do a JNDI lookup to find that bean. You can use the SessionContext you injected as the context for the JNDI lookup or grab an InitialContext.

olendvcook
  • 86
  • 4
  • before using SessionContext, i tried this : @Inject private LogBookService logBookService ; for (LogBookEntity log : LogBookEntities) {logBookService.writelogNewTransaction(log);} but it doesn't work,I assume that the call of the method ‘writelogNewTransaction()’ will start a new transaction context. But when I test this code I see the method ‘writelogNewTransaction(log)’ is never run in a separate transaction – the transactionAttributeType ‘REQUIRES_NEW’ will be ignored by the EJB container! – oumina Dec 19 '19 at 11:40
  • hmm, that looks like it should be working, and it's a little hard to debug without trace. Do you have anything in ibm-ejb-jar.xml and/or installed the application with metadata-complete set to true? – olendvcook Dec 19 '19 at 16:58
  • there is no either ibm-ejb-jar.xml nor metadata-complete=true , i think i have the same probleme as this : https://blog.imixs.org/2014/02/20/ejb-transactionattributetype-requires_new/ , as you said , i added writelogNewTransaction in the GalaxyService inetrface, and the implementation in GalaxyServiceImpl, and it works. – oumina Dec 21 '19 at 21:29