【问题标题】:Hibernate & Derby: hbm2dll does not create sequencesHibernate & Derby:hbm2dll 不创建序列
【发布时间】:2012-01-20 10:34:17
【问题描述】:

我正在使用 hibernate3-maven-plugin 调用 hbm2ddl 为我的实体导出 ddl。

然后dbmaintain 使用此 ddl 文件来初始化嵌入式 derby 数据库。

但是当我使用这个数据库启动我的 Java Enterprise 应用程序时,我收到以下错误:

16:48:41.714 ERROR [main] o.h.util.JDBCExceptionReporter: SEQUENCE 'HIBERNATE_SEQUENCE' does not exist.

...这是正确的,因为生成的 ddl 文件中与我的实体没有直接关系的唯一代码如下:

create table hibernate_unique_key (
     next_hi integer 
);

insert into hibernate_unique_key values ( 0 );

该文件不包含任何关于序列的内容。

如果我不使用dbmaintain 并将hibernate.hbm2ddl.auto 设置为update,它就可以工作,但这不是我想在生产中使用的东西(因为大多数消息来源都反对它)。

hbm2ddl 生成的 ddl 不应该包含休眠所需的所有内容吗?

Maven 配置:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
        <configuration>
        <components>
            <component>
                <name>hbm2ddl</name>
                <implementation>jpaconfiguration</implementation>
            </component>
        </components>
        <componentProperties>
            <persistenceunit>MyPersistenceUnitName</persistenceunit>
            <outputfilename>schema.ddl</outputfilename>
            <drop>false</drop>
            <create>true</create>
            <export>false</export>
            <format>true</format>
        </componentProperties>
    </configuration>
</plugin>

persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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_2_0.xsd"
             version="2.0">
    <persistence-unit name="MyPersistenceUnitName">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:app/jdbc/MyPersistenceUnitName</jta-data-source>
        <properties>
            <property name="hibernate.id.new_generator_mappings" value="true" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
            <property name="javax.persistence.validation.group.pre-persist" value="some.ServerValidation" />
            <property name="javax.persistence.validation.group.pre-update" value="some.ServerValidation" />
        </properties>
    </persistence-unit>
</persistence>

【问题讨论】:

    标签: hibernate maven jpa-2.0 java-ee-6 derby


    【解决方案1】:

    我终于弄明白了:

    问题是(最新的)hibernate3-maven-plugin 的依赖关系完全过时,无法处理我的 JPA 2.0 注释。

    我通过调用mvn -X hibernate3:hbm2ddl 获得了插件依赖项的列表,并通过手动将插件的所有休眠依赖项覆盖到最新版本来解决了这个问题:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>hibernate3-maven-plugin</artifactId>
        <configuration>
            <components>
                <component>
                    <name>hbm2ddl</name>
                    <implementation>jpaconfiguration</implementation>
                </component>
            </components>
            <componentProperties>
                <persistenceunit>MyPersistenceUnitName</persistenceunit>
                <outputfilename>schema.ddl</outputfilename>
                <drop>false</drop>
                <create>true</create>
                <export>false</export>
                <format>true</format>
            </componentProperties>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-tools</artifactId>
                <version>3.2.4.GA</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>3.6.8.Final</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>3.6.3.Final</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-annotations</artifactId>
                <version>3.5.6-Final</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-validator</artifactId>
                <version>4.2.0.Final</version>
            </dependency>
        </dependencies>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-26
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 2011-04-05
      • 2019-08-16
      相关资源
      最近更新 更多