Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jetty上H2/Hibernate JPA的Hikari池-SQL错误表不存在_Hibernate_Jpa_Jetty_H2_Hikaricp - Fatal编程技术网

Jetty上H2/Hibernate JPA的Hikari池-SQL错误表不存在

Jetty上H2/Hibernate JPA的Hikari池-SQL错误表不存在,hibernate,jpa,jetty,h2,hikaricp,Hibernate,Jpa,Jetty,H2,Hikaricp,我正在使用Hikari在Jetty 9服务器上为一个webapp共享H2内存连接 工作很好,直到我离开几个小时,让它闲置。当我返回时,所有数据库查询都会告诉我,当我重新加载页面时,表不存在。我不确定这是哪里出了问题,我假设连接仍然很好,因为它正在尝试运行查询,但是出现了奇怪的错误 以下是我的设置: jetty-env.xml: <Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"> <New

我正在使用Hikari在Jetty 9服务器上为一个webapp共享H2内存连接

工作很好,直到我离开几个小时,让它闲置。当我返回时,所有数据库查询都会告诉我,当我重新加载页面时,表不存在。我不确定这是哪里出了问题,我假设连接仍然很好,因为它正在尝试运行查询,但是出现了奇怪的错误

以下是我的设置:

jetty-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>

jdbc/myds
1.
org.h2.jdbcx.JdbcDataSource-
网址
jdbc:h2:mem:test\u mem
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"/>-->

org.hibernate.jpa.HibernatePersistenceProvider
jdbc/myds
net.b.Configuration
net.b.Form
净值
net.b.Translation
示例查询:

TypedQuery<String> query = em.createQuery(
                    "SELECT t.value FROM Translation t WHERE t.key = :key", String.class);
 query.setParameter("key", key);
 result = query.getSingleResult();
TypedQuery query=em.createQuery(
“从翻译t中选择t.value,其中t.key=:key”,String.class);
query.setParameter(“key”,key);
结果=query.getSingleResult();

这个REST端点将工作100次,但经过一段空闲时间后,我得到一个异常,表“TRANSLATION”不存在。给出了什么?

您的答案可以在这里找到。您需要使用
jdbc:h2:mem:test;DB\u CLOSE\u DELAY=-1,否则数据库和表将在最后一个连接关闭后立即消失。

您的答案可以在这里找到。您需要使用
jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
,否则数据库和表将在最后一个连接关闭后立即消失