Error using Hibernate with H2 in memory database

前端 未结 1 399
清酒与你
清酒与你 2020-12-31 04:00

I\'m working with Hibernate. How can I configure my persistence.xml to have an H2 in-memory database?

My persistence.xml is:



        
相关标签:
1条回答
  • 2020-12-31 04:35

    You should set hibernate.hbm2ddl.auto property to "create" the first time you run your application, to create the tables

    <property name="hibernate.hbm2ddl.auto" value="create" />
    

    and then (if you don't want the tables to be recreated and emptied every time you start) set it to "validate".

    <property name="hibernate.hbm2ddl.auto" value="validate" />
    

    To create the schema automatically, add if-not-exists to your connection url like this:

    <property name="hibernate.connection.url" value="jdbc:h2:~/<filename>;INIT=CREATE SCHEMA IF NOT EXISTS <schema_name>" />
    
    0 讨论(0)
提交回复
热议问题