...without actually reading and parsing the persistence.xml
I can retrieve the name of the persistence unit of an EntityManager
using the p
You need to:
EntityManager
to EntityManagerImpl
(the Hibernate implementation)getFactory()
EntityManagerFactory
to HibernateEntityManagerFactory
getSessionFactory()
and cast it to SessionFactoryImpl
getConnectionProvider()
and cast it to the correct implementation. You can see the implementations here. I'll assume that it's a DatasourceConnectionProvider
getDataSource()
and you're done.Unfortunately, you must use the Hibernate API, as there's no way to retrieve the DataSource using the JPA API.