从 DataSource 检测 Hibernate 方言

Detect Hibernate dialect from DataSource

这样解析的数据源:

final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
dsLookup.setResourceRef(true);

entityManagerFactoryBean.setDataSource(dsLookup.getDataSource("jdbc/translation"));
entityManagerFactoryBean.getJpaPropertyMap().
     put(Environment.DIALECT_RESOLVERS, StandardDialectResolver.class.getCanonicalName());

会给我这个例外:

Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

不幸的是我不知道具体的数据库是什么。

如何让hibernate决定使用什么方言?

适用于 Hibernate 4,不确定他们为什么放弃该功能。