当我尝试将Hibernate与本地Derby-Database一起使用时,我总是会对错误的持久性提供程序进行三次警告:
[WARN] HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
[WARN] HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
[WARN] HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
我找不到任何理由,因为我的persistence.xml(项目中唯一的persistence.xml)如下所示:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="performanzdb" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>...</class>
<properties>
<property name="hibernate.connection.url" value="myUrl;create=true" />
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
因此定义了正确的持久性提供程序org.hibernate.jpa.HibernatePersistenceProvider
。
我可以想象的另一个原因是我的一些maven依赖项是错误的,但这些只是最新的entitymanager
- 和jpamodelgen-dependencies
:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.7.Final</version>
</dependency>
除了开头的警告和错误:
[ERROR] HHH015011: Unable to locate static metamodel field : package.class_#field
不时发生新定义的字段,Hibernate运行正常,所有内容都写在数据库中。
有谁知道,为什么使用了错误的PersistenceProvider
或为什么会出现这种错误?
答案 0 :(得分:1)
答案 1 :(得分:0)
使用新的基于maven的Spring Boot项目,包括JPA依赖项,当slf4j级别为INFO时,我仍然会看到这些警告日志行。
14:04:47.990 [main] WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. 14:04:47.990 [main] WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead. 14:04:47.990 [main] WARN o.hibernate.ejb.HibernatePersistence - HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
我找到了这个解决方案https://hibernate.atlassian.net/browse/HHH-9141并在创建实体管理器工厂之前添加了一段代码:
public EntityManager create() {
if (AbstractBaseForJUnit.EMF == null) {
PersistenceProviderResolverHolder.setPersistenceProviderResolver(new PersistenceProviderResolver() {
private final List<PersistenceProvider> providers_ = Arrays.asList((PersistenceProvider) new HibernatePersistenceProvider());
@Override
public void clearCachedProviders() {
// TODO Auto-generated method stub
}
@Override
public List<PersistenceProvider> getPersistenceProviders() {
return providers_;
}
});
if (StringUtils.isBlank(AbstractBaseForJUnit.PU_NAME)) {
AbstractBaseForJUnit.PU_NAME = CoreProperties.Features.PERSISTENCE_UNIT_NAME;
}
AbstractBaseForJUnit.EMF = Persistence.createEntityManagerFactory(AbstractBaseForJUnit.PU_NAME);
}
if (this.EM == null) {
this.EM = AbstractBaseForJUnit.EMF.createEntityManager();
this.EM.setFlushMode(FlushModeType.COMMIT);
}
return EM;
}
还改变了我的persistence.xml
&LT;提供商GT; org.hibernate.jpa.HibernatePersistenceProvider&LT; /提供商GT;
现在没有警告了。