我正在使用Hikari在Jetty 9服务器中为网络应用程序汇集H2内存连接。
效果很好,直到我离开几个小时并让它闲置。当我回来时,我的所有数据库查询告诉我,当我重新加载页面时表不存在。我不确定这出错的地方,我假设连接仍然很好,因为它正在尝试运行查询,但是获得了奇怪的错误。
这是我的设置:
码头-env.xml:
<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
<New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>jdbc/myds</Arg>
<Arg>
<New class="com.zaxxer.hikari.HikariDataSource">
<Arg>
<New class="com.zaxxer.hikari.HikariConfig">
<Set type="int" name="maximumPoolSize">1</Set>
<Set name="dataSourceClassName">
org.h2.jdbcx.JdbcDataSource-
</Set>
<Call name="addDataSourceProperty">
<Arg>url</Arg>
<Arg>jdbc:h2:mem:test_mem</Arg>
</Call>
</New>
</Arg>
</New>
</Arg>
</New>
</Configure>
的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="MyJPAJAXRS" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>jdbc/myds</non-jta-data-source>
<class>net.b.Configuration</class>
<class>net.b.Form</class>
<class>net.b.FormValue</class>
<class>net.b.Translation</class>
<properties>
<property name="javax.persistence.schema-generation.database.action"
value="drop-and-create"/>
<property name="javax.persistence.sql-load-script-source" value="META-INF/seed.sql"/>
</properties>
</persistence-unit>
</persistence>
<!--<property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>-->
<!--<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test_mem"/>-->
<!--<property name="javax.persistence.schema-generation.create-source"-->
<!--value="metadata-then-script"/>-->
示例查询:
TypedQuery<String> query = em.createQuery(
"SELECT t.value FROM Translation t WHERE t.key = :key", String.class);
query.setParameter("key", key);
result = query.getSingleResult();
此REST端点将工作100次,但在一些空闲时间后,我得到表“TRANSLATION”不存在的异常。是什么给了什么?