开发者

H2 database In memory - Init schema via Spring/Hibernate

开发者 https://www.devze.com 2022-12-15 01:56 出处:网络
I have a Spring/Hibernate application with H2 database and I have a few issues with configuring H2 to run in an embedded mode (in memory):

I have a Spring/Hibernate application with H2 database and I have a few issues with configuring H2 to run in an embedded mode (in memory):

1. I want spring to start the H2 database so I created the following Spring beans:

<bean id="org.h2.tools.Server" class="org.h2.tools.Server"
        factory-method="createTcpServer" init-method="start" destroy-method="stop">
        <constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />
    </bean>

    <bean id="org.h2.tools.Server-WebServer" class="org.h2.tools.Server"
        factory-method="createWebServer" init-method="start">
        <constructor-arg value="-web,-webAllowOthers,true,-webPort,8082" />
    </bean>

Do I need to use the tcp server at all for in-memory use? Is this the correct configuration for in memory?

2.With the above configuration - How can I create and init the database schema before Hibernate is started? I know that HSQLDB has a URL property that states the na开发者_如何学Pythonme of the creation script. Is there a similar way here?

Thanks for the help


Hibernate has a property called schemaUpdate. Set it on your SessionFactory so that the database is created on initialization.

<property name="schemaUpdate" value="true" />

If you are using JPA, then there is a generateDdl property that is to be set on the JpaVendorAdapter

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号