首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使HSQL数据库在LightAdmin (Spring/JPA/Hibernate)中保持不变

使HSQL数据库在LightAdmin (Spring/JPA/Hibernate)中保持不变
EN

Stack Overflow用户
提问于 2014-03-13 00:00:55
回答 1查看 1.1K关注 0票数 0

我试图更改默认的LightAdmin设置,该设置使用内存中的HSQL数据库来使用文件HSQL数据库。

persistence.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
    <persistence-unit name="DEMO" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>org.lightadmin.demo.model.Address</class>
        <class>org.lightadmin.demo.model.Customer</class>
        <class>org.lightadmin.demo.model.EmailAddress</class>
        <class>org.lightadmin.demo.model.Product</class>
        <class>org.lightadmin.demo.model.Order</class>
        <class>org.lightadmin.demo.model.LineItem</class>
        <class>org.lightadmin.demo.model.DiscountProgram</class>
    </persistence-unit>
</persistence>

Springcontext.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="org.lightadmin.demo.service"/>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
          p:persistenceUnitName="DEMO" p:dataSource-ref="dataSource">
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="generateDdl" value="true"/>
                <property name="database" value="HSQL"/>
            </bean>
        </property>
    </bean>

    <jdbc:embedded-database id="dataSource" type="HSQL">
        <jdbc:script location="classpath:db/schema.sql" encoding="UTF-8"/>
        <jdbc:script location="classpath:db/data.sql" encoding="UTF-8"/>
    </jdbc:embedded-database>

</beans>

我尝试过的内容:在persistence.xml中提供了以下属性:

代码语言:javascript
复制
<property name="hibernate.connection.url" value="jdbc:hsqldb:file:database"/>
<property name="hibernate.hbm2ddl.auto" value="update" />

但它没有尽到自己的职责。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-13 00:47:30

找到一个解决方案,将spring上下文更改为:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
        p:persistenceUnitName="DEMO">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" />
                <property name="generateDdl" value="true" />
                <property name="database" value="HSQL" />
            </bean>
        </property>
    </bean>

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
        <property name="url" value="jdbc:hsqldb:file:build_database" />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>

</beans>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22366461

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档