Hibernate has the option to auto-detetect the hibernate.dialect
. How can I retrieve that auto-detected value? I was unable to find any information on this.
Asked
Active
Viewed 6,767 times
13

Aleksandr M
- 24,264
- 12
- 69
- 143

user101442
- 2,517
- 3
- 20
- 12
2 Answers
20
You can retrieve it from the SessionFactory but you'll need to cast it to SessionFactoryImplementor first:
SessionFactory sessionFactory = ...; // you should have this reference
Dialect dialect = ((SessionFactoryImplementor) sessionFactory).getDialect();
The above will retrieve the dialect instance currently being used by session factory, which is the auto detected instance if it wasn't explicitly specified via properties.

ChssPly76
- 99,456
- 24
- 206
- 195
7
From Hibernate 5.2+ the most appropriate way to get Dialect is:
EntityManager em ...
Session session = em.unwrap(Session.class);
SessionFactory sessionFactory = session.getSessionFactory();
Dialect dialect = ((SessionFactoryImplementor) sessionFactory).getJdbcServices().getDialect();

MhagnumDw
- 893
- 1
- 10
- 12