H2 in-mem-DB与hibernate设置为创建给我表未找到错误

pas*_*oop 6 hibernate h2

我想在内存DB中设置一个带有hibernate,spring mvc和H2的项目(现在).当一切都启动(在码头)我得到错误,说表不存在.

这是我得到的错误:

Okt 09, 2013 3:42:47 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: HHH000227: Running hbm2ddl schema export
Okt 09, 2013 3:42:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: HHH000389: Unsuccessful: alter table PUBLIC.Object drop constraint FK_9sd2x4ehbugdjyrp1xqmsjw00
Okt 09, 2013 3:42:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
ERROR: Tabelle "OBJECT" nicht gefunden
Table "OBJECT" not found; SQL statement:
...
Run Code Online (Sandbox Code Playgroud)

如果我没有像这样设置Hibernate,那就没关系:

hibernate.hbm2ddl.auto=create
Run Code Online (Sandbox Code Playgroud)

H2的连接字符串是这样的:

jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=TRUE
Run Code Online (Sandbox Code Playgroud)

我可以使用IntelliJ连接到数据库,所以它就在那里..

我希望Hibernate为我生成表,然后是约束和其他任何后续但由于某种原因它不会那样做.它可能是用户权限吗?这些是我设置的用户设置:

jdbc.user=sa
jdbc.pass=
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!谢谢 :)

UPDATE

如果我将连接字符串更改为:

jdbc.url=jdbc:h2:~/db/database.db;DB_CLOSE_ON_EXIT=TRUE;INIT=create schema IF NOT EXISTS generic;
Run Code Online (Sandbox Code Playgroud)

它似乎工作.但是为什么它在内存中不起作用以及为什么它在我将默认模式设置为"公共"之前不起作用(这已经是我已经想到的可能只是将我的东西转储到那里......)IDK!

sea*_*anf 0

这听起来像https://hibernate.atlassian.net/browse/HHH-7002

就我而言,我能够通过以下属性将 Hibernate 配置为使用以下类来消除hibernate.dialect异常persistence.xml

import org.hibernate.dialect.H2Dialect;

// This class is a workaround for https://hibernate.atlassian.net/browse/HHH-7002
public class CustomH2Dialect extends H2Dialect {

    @Override
    public String getDropSequenceString(String sequenceName) {
        // Adding the "if exists" clause to avoid warnings
        return "drop sequence if exists " + sequenceName;
    }

    @Override
    public boolean dropConstraints() {
        // We don't need to drop constraints before dropping tables; that just
        // leads to error messages about missing tables when we don't have a
        // schema in the database
        return false;
    }

    @Override
    public boolean supportsIfExistsBeforeTableName() {
        return true;
    }

    @Override
    public boolean supportsIfExistsAfterTableName() {
        return false;
    }

    @Override
    public String getCascadeConstraintsString() {
        return " CASCADE ";
    }
}
Run Code Online (Sandbox Code Playgroud)

(感谢/sf/answers/1448883761/