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
Hibernate 使用HSQL内存数据库作为JPA数据源_Hibernate_Jpa_Persistence_Jpa 2.0_Hsqldb - Fatal编程技术网

Hibernate 使用HSQL内存数据库作为JPA数据源

Hibernate 使用HSQL内存数据库作为JPA数据源,hibernate,jpa,persistence,jpa-2.0,hsqldb,Hibernate,Jpa,Persistence,Jpa 2.0,Hsqldb,我有一个内存中的数据源: java.sql.Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", ""); emf = Persistence.createEntityManagerFactory("manager"); 但现在我被卡住了。我想将其用作J2SE应用程序中的JPA数据源。我浏览了整个网站,但所有信息都与J2EE相关 <persistence xmlns="

我有一个内存中的数据源:

java.sql.Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:testdb", "sa", "");            
emf = Persistence.createEntityManagerFactory("manager");
但现在我被卡住了。我想将其用作J2SE应用程序中的JPA数据源。我浏览了整个网站,但所有信息都与J2EE相关

<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="manager">

        <jta-data-source>/*What to enter here?*/</jta-data-source>

        <properties>

            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />

        </properties>

    </persistence-unit>

</persistence>

/*在这里输入什么*/
/*在这里输入什么*/

没什么。在Java SE环境中,您必须使用JPA提供商提供的内置连接池,设置如下所示:

<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="manager" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.acme.Foo</class>
    ...
    <properties>
      <property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:testdb"/>
      <property name="javax.persistence.jdbc.user" value="sa"/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

org.hibernate.ejb.HibernatePersistence
com.acme.Foo
...

谢谢,它很有效。我现在有另一个问题: