Ravi Jain
Ravi Jain

Reputation: 1482

Creating Hibernate SessionFactory using persistence.xml

Is is possible to create hibernate SessionFactory object from persistence.xml. Usually we create EntityManagerFactory using persistence.xml , I would like to know if SessionFactory could be created.
I googled it but did not find any useful resource.

Upvotes: 2

Views: 2417

Answers (1)

Lawrence McAlpin
Lawrence McAlpin

Reputation: 2785

If you are using a recent version of Hibernate that supports JPA 2.1, you can use the unwrap method on the EntityManagerFactory: https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/EntityManagerFactory.html#unwrap(java.lang.Class)

If what you are really after is a Hibernate Session object, you can get that from the EntityManager object using the getDelegate method.

Upvotes: 2

Related Questions