开发者

Can I use multiple data sources in a single stateless session bean (EJB3)?

Does anybody know whether I can use multiple data sources in a single stateless session bean in EJB3?

I want to develop a session bean to aggregate a lot data and return, but these data comes from 2 data sources, is t开发者_开发问答his possible?

Can someone provide a sample on this?

Thanks very much !


Yes, as long as the DataSources are both capable of being enlisted in the same transaction (i.e., are XA capable). Simply create two separate resources, and bind them to separate DataSource objects.

@Resource
private DataSource ds1;
@Resource
private DataSource ds2;

public void businessMethod() {
    // ...use ds1 and ds2...
}

Unfortunately, data source creation and EJB bindings are vendor-specific, so it's not really possible to provide an example unless you mention which application server you're using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜