开发者

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

开发者 https://www.devze.com 2022-12-31 13:34 出处:网络
Does anybody know whether I can use multiple data sources in a single stateless session bean in 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

精彩评论

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