Using HSQL in-memory database as JPA datasource

后端 未结 1 1475
谎友^
谎友^ 2021-01-01 13:15

I have an in-memory data source:

java.sql.Connection c = DriverManager.getConnection(\"jdbc:hsqldb:mem:testdb\", \"sa\", \"\");            
emf = Persistence         


        
相关标签:
1条回答
  • 2021-01-01 14:05

    /*What to enter here?*/

    Well, nothing. In a Java SE environment, you'll have to use the built-in connection pool from your JPA provider and the setup looks like this:

    <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>
    
    0 讨论(0)
提交回复
热议问题