在IntelliJ中使用JHipster 4.2.0,jpa控制台无法正常工作:
javax.persistence.PersistenceException: [PersistenceUnit: Entities] Unable to build Hibernate SessionFactory
java.lang.RuntimeException: org.hibernate.cache.NoCacheRegionFactoryAvailableException: Second-level cache is used in the application, but property hibernate.cache.region.factory_class is not given; please either disable second level cache or set correct region factory using the hibernate.cache.region.factory_class setting and make sure the second level cache provider (hibernate-infinispan, e.g.) is available on the classpath.
在application-dev.yml中,设置了factory_class。
hibernate.cache.region.factory_class: io.github.jhipster.config.jcache.NoDefaultJCacheRegionFactory
有什么方法可以解决这个问题吗?
答案 0 :(得分:1)
我的解决方案是在resources文件夹中创建这个persistence.xml文件,但你需要修复以满足你的需求,在我的情况下我使用的是postgresSQL,但你可以使用你的数据库类型进行配置:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="project name" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!-- non-jta-datasource>jdbc/arquillian</non-jta-datasource -->
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.use_sql_comments" value="false"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"/>
<property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/dialysis-dev"/>
<property name="javax.persistence.jdbc.user" value="develop"/>
<property name="javax.persistence.jdbc.password" value="admpostgres"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="hibernate.ejb.naming_strategy" value="org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy"/>
<property name="hibernate.ddl-auto" value="none"/>
</properties>
</persistence-unit>
</persistence>
然后在视图菜单/工具Windows / Persistence中,您将能够看到此持久性文件。因此,右键单击即可看到JPA控制台。在我的情况下工作完美。
使用这种方式您不需要分配数据源,因为IntelliJ IDEA所需的所有配置都在上面的文件中。顺便说一下,这是在Intellij IDEA的Ultimate版本中测试的。