oumina
oumina

Reputation: 31

global transaction websphere 8.5.5.11 ejb

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?

Upvotes: 0

Views: 215

Answers (1)

olendvcook
olendvcook

Reputation: 86

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.

Upvotes: 1

Related Questions