Retrieve auto-detected hibernate dialect

╄→尐↘猪︶ㄣ 提交于 2019-11-30 01:40:15

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/1571928/retrieve-auto-detected-hibernate-dialect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!