Note that there are some explanatory texts on larger screens.

plurals
  1. POChange hibernate.connection.url from within Spring
    primarykey
    data
    text
    <p>I am using Hibernate in combination with Spring. As database I am currently using HSQL, which stores its data in a file (like SQLite). The path to the HSQL file is currently hard-coded in the persistence.xml. How can I access and change this value at runtime, so a user can load and save from/to an arbitrary HSQL file?</p> <p><strong>persistence.xml:</strong> </p> <pre><code>&lt;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_1_0.xsd" version="1.0"&gt; &lt;persistence-unit name="something-unit"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;properties&gt; &lt;property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver" /&gt; &lt;property name="hibernate.connection.url" value="jdbc:hsqldb:file:~/something-db/somethingdb" /&gt; &lt;property name="hibernate.connection.username" value="sa" /&gt; &lt;property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /&gt; &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>Spring <strong>applicationContext.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:data="http://www.springframework.org/schema/data/jpa" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt; &lt;!-- Database Setup --&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt; &lt;property name="persistenceUnitName" value="something-unit" /&gt; &lt;/bean&gt; &lt;data:repositories base-package="com.something.playlist"/&gt; &lt;!-- Transaction Setup --&gt; &lt;tx:annotation-driven/&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre> <p>Thanks for any hint!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload