【发布时间】:2011-04-19 15:54:01
【问题描述】:
我有一个使用 maven 构建的项目,我需要使用 hibernate3-maven-plugin 中的 hbm2ddl 工具生成一个模式。
我需要用一个名为 Order 的表创建数据库,就像 SQL 关键字一样,我不知道如何让 maven 在生成脚本时引用这个表。我已经进行了搜索,我发现在 hibernate 中有一个属性可以告诉 hbm2ddl 工具,但我不能告诉插件使用它:
<property name="hbm2ddl.keywords">auto-quote</property>
如果我不引用表格,hbm2ddl 会生成一个脚本:
create table Order (orderId varchar(36) not null, orderCode integer, customer varchar(36) not null, supplier varchar(36) not null, product varchar(36) not null, forecast float, dateRaised date not null, dateDispatched date, dateReceived date, quantityOrdered double precision not null, quantitySent double precision, primary key (orderId)) ENGINE=InnoDB;
无法编译(由于明显的语法错误):
02:51:41,264 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - Unsuccessful: create table Order (orderId varchar(36) not null, orderCode integer, customer varchar(36) not null, supplier varchar(36) not null, product varchar(36) not null, forecast float, dateRaised date not null, dateDispatched date, dateReceived date, quantityOrdered double precision not null, quantitySent double precision, primary key (orderId)) ENGINE=InnoDB
02:51:41,264 ERROR org.hibernate.tool.hbm2ddl.SchemaExport - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Order (orderId varchar(36) not null, orderCode integer, customer varchar(36) not' at line 1
这是 pom.xml 文件的一部分:
<configuration>
<components>
<component>
<name>hbm2java</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>src/main/java</outputDirectory>
</component>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>src/main/resources</outputDirectory>
</component>
<component>
<name>hbm2doc</name>
<implementation>annotationconfiguration</implementation>
<outputDirectory>docs/html/hibernate</outputDirectory>
</component>
</components>
<componentProperties>
<create>true</create>
<drop>true</drop>
<configurationfile>src/main/resources/hibernate.cfg.xml</configurationfile>
<propertyfile>src/main/resources/database.properties</propertyfile>
<jdk5>true</jdk5>
<outputfilename>amasbe_db.sql</outputfilename>
</componentProperties>
</configuration>
非常感谢任何提示或帮助。
谢谢!
【问题讨论】:
标签: hibernate maven-2 keyword hbm2ddl