开发者

Retrieve auto-detected hibernate dialect

开发者 https://www.devze.com 2022-12-08 08:56 出处:网络
Hibernate has the option to auto-detetect the hibernate.dialect. How can I retrieve that auto-detected v开发者_开发问答alue? I was unable to find any information on this.You can retrieve it from the S

Hibernate has the option to auto-detetect the hibernate.dialect. How can I retrieve that auto-detected v开发者_开发问答alue? I was unable to find any information on this.


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.


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号