How to get Hibernate dialect during runtime

前端 未结 3 1615
醉酒成梦
醉酒成梦 2021-01-17 14:14


In my application, I use Hibernate with SQL Server database, so I set



        
3条回答
  •  逝去的感伤
    2021-01-17 14:59

    The following works well for me for accessing the dialect in a Java EE application running in WildFly 14:

    import org.hibernate.Session;
    import org.hibernate.dialect.Dialect;
    import org.hibernate.internal.SessionFactoryImpl;
    
    ...
    
    @PersistenceContext
    private EntityManager entityManager;
    
    ...
    
    final Session session = (Session) entityManager.getDelegate();
    final SessionFactoryImpl sessionFactory = (SessionFactoryImpl) session.getSessionFactory();
    final Dialect dialect = sessionFactory.getJdbcServices().getDialect();
    logger.info("Dialect: {}", dialect);
    

    You need to add hibernate-core dependency with provided scope to pom.xml.

提交回复
热议问题