Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HSQL in-memory database as JPA datasource

Tags:

I have an in-memory data source:

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

But now I'm stuck. I want to use it as a JPA data source in a J2SE application. I've scoured the entire web but all info is related to 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> 
like image 866
Bart van Heukelom Avatar asked Sep 27 '10 13:09

Bart van Heukelom


People also ask

What is HSQLDB in-memory database?

HSQLDB (HyperSQL Database) HSQLDB is an open source project, also written in Java, representing a relational database. It follows the SQL and JDBC standards and supports SQL features such as stored procedures and triggers. It can be used in the in-memory mode, or it can be configured to use disk storage.

What is Spring JPA Hibernate DDL Auto?

spring. jpa. hibernate. ddl-auto (enum) is a Hibernate feature that controls the behavior in a more fine-grained way.


1 Answers

/*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> 
like image 110
Pascal Thivent Avatar answered Sep 19 '22 14:09

Pascal Thivent