【发布时间】:2019-03-04 15:46:00
【问题描述】:
我正在尝试使用 Intellij Idea Ultimate 中的 JPA 控制台来测试查询。该项目使用 JHipster 5.7.0 生成,并使用带有 Hazelcast 的 H2 内存数据库。
生成的 application-dev.yml:
...
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:appointmentservice;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: appointmentservice
password:
hikari:
auto-commit: false
h2:
console:
enabled: true
jpa:
database-platform: io.github.jhipster.domain.util.FixedH2Dialect
database: H2
show-sql: false
properties:
hibernate.id.new_generator_mappings: true
hibernate.connection.provider_disables_autocommit: true
hibernate.cache.use_second_level_cache: true
hibernate.cache.use_query_cache: false
hibernate.generate_statistics: true
hibernate.cache.region.factory_class: com.hazelcast.hibernate.HazelcastCacheRegionFactory
hibernate.cache.hazelcast.instance_name: appointmentservice
hibernate.cache.use_minimal_puts: true
hibernate.cache.hazelcast.use_lite_member: true
...
我在资源目录中创建了以下 persistence.xml:
<?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="appointmentservice" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:appointmentservice"/>
<property name="javax.persistence.jdbc.user" value="appointmentservice"/>
<property name="hibernate.id.new_generator_mappings" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="false"/>
<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.cache.region.factory_class" value="com.hazelcast.hibernate.HazelcastCacheRegionFactory"/>
<property name="hibernate.cache.hazelcast.instance_name" value="appointmentservice"/>
<property name="hibernate.cache.use_minimal_puts" value="true"/>
<property name="hibernate.cache.hazelcast.use_lite_member" value="true"/>
</properties>
</persistence-unit>
</persistence>
问题: 在 Intellij 持久性视图中,当单击约会服务时,所有实体都会显示。但是,当我右键单击它并打开 JPA 控制台时,所有查询都声称未找到表。
例如
jpa-ql> select a from Address a
[2019-03-04 16:03:57] [42S02] Table "ADDRESS" not found; SQL statement:
[2019-03-04 16:03:57] select address0_.id as id1_1_, address0_.active as active2_1_, address0_.city as city3_1_, address0_.clientAccount_id as clientAc9_1_, address0_.country as country4_1_, address0_.institution_id as institu10_1_, address0_.location_id as locatio11_1_, address0_.jhi_number as jhi_numb5_1_, address0_.street as street6_1_, address0_.supplement as suppleme7_1_, address0_.zip as zip8_1_ from address address0_ [42102-197]
如果有人能给我提示我做错了什么,或者是否有任何适合我的案例的好示例 persistence.xml 文件,我将不胜感激。 提前致谢
编辑: 感谢所有的回复! - 我按照@Gaël Marziou 的建议删除了 persistence.xml 并使用 tcp URL 连接到 Intellij 中的数据源。我现在可以在那里浏览表格内容。 然后我必须将数据源分配给 Intellij 持久性视图中的 entityManagerFactory。此外,我需要使用与 application.yml 中相同的 NamingStrategie。
【问题讨论】:
-
这里没有错。但是,您正在使用仅对正在运行的进程可见的内存数据库。它不能从外部访问。因此,您不会在 Intellij 中看到相同的数据库。
-
所以这也意味着即使应用程序运行我也无法访问它?
-
否,除非您使用 tCP 端口配置它(如下面的答案所述)。或者只是不覆盖该属性。我还建议放弃
persistence.xml,转而使用application.properties。
标签: spring hibernate jpa intellij-idea jhipster