休眠和Derby:hbm2dll 不创建序列
我正在使用 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 );
The file does' t 包含任何有关序列的内容。
如果我不使用 dbmaintain 并仅将 hibernate.hbm2ddl.auto 设置为 update ,它就可以工作,但这不是我想在生产中使用的(正如大多数消息来源建议反对的那样)。
hbm2ddl
生成的 ddl 不应该包含 hibernate 所需的所有内容吗?
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于弄清楚了:
问题是(最新)hibernate3-maven-plugin 已经完全过时了,无法处理我的 JPA 2.0 注释。
我通过调用 mvn -X hibernate3:hbm2ddl 获得了插件依赖项列表,并通过手动将插件的所有 hibernate 依赖项覆盖为最新版本来修复问题:
I was finally able to figure it out:
The problem was that the dependencies of the (latest) hibernate3-maven-plugin are completely outdated and could not handle my JPA 2.0 annotations.
I got a list of the plugin's dependencies by calling
mvn -X hibernate3:hbm2ddl
and fixed the problem by manually overriding all hibernate dependencies of the plugin to the latest versions: