Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2084

Get the url that the Connection uses to connect the database

I'm trying to get the url that the Connection uses to connect the database as following :

getEntityManager().unwrap(SessionImplementor.class).connection().getMetaData().getURL();

But I get this error :

java.lang.IllegalStateException: No transactional EntityManager available

How can I solve this ?

Edit:

I don't understand why this question was considered as duplicated to a Hibernate solution, I'm using JPA, so I'm trying to get the url using entityManager and not sessionFactory.

Upvotes: 0

Views: 220

Answers (2)

Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2084

The solution was to add the @Transactional annotation.

Upvotes: 1

R. Daumann
R. Daumann

Reputation: 86

The SessionImplementor Interface is form Hibernate, so which JPA Implementation are you using then?

Upvotes: 0

Related Questions