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

我有一个内存数据源:

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>

/*What to enter here?*/

好吧,没有。在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>
翻译自:https://stackoverflow.com/questions/3804409/using-hsql-in-memory-database-as-jpa-datasource

转载注明原文:hibernate – 使用HSQL内存数据库作为JPA数据源