【发布时间】: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