1tox
1tox

Reputation: 337

Get javax.sql.DataSource from javax.persistence.EntityManager

I have to deal with an API which need to be provided a DataSource as a parameter. The problem is I'm accessing it from a context that provides an EntityManager or a PersistentContext, which do not appear to expose any DataSource through its methods. How is it possible to programmatically retrieve the underlying DataSource from an EntityManager ?

Upvotes: 1

Views: 3356

Answers (1)

1tox
1tox

Reputation: 337

Solution is injecting datasource this way :

@Resource(name = "jdbc/...")
private DataSource dataSource;

and then providing the datasource as an argument to the API.

Upvotes: 2

Related Questions