hibernate3-maven-plugin hbm2ddlを使用してテーブルを引用するにはどうすればよいですか?

StackOverflow https://stackoverflow.com/questions/3836085

質問

Mavenで構築しているプロジェクトがあり、Hibernate3-Maven-PluginのHBM2DDLツールを使用してスキーマを生成する必要があります。

呼ばれるテーブルを使用してデータベースを作成する必要があります 注文 SQLキーワードのように、このテーブルがスクリプトを生成しているときにこのテーブルを引用させる方法がわかりません。私は検索をしました、そして、私はこれにHBM2DDLツールを伝えるためにHibernateにプロパティがあることがわかりましたが、私はそれを使用するようにプラグインに伝えることはできません:

<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>

ヒントやヘルプは本当に感謝しています。

ありがとうございました!

役に立ちましたか?

解決

afaik、 hbm2ddl.keywords Nhibernate機能であり、Hibernateによってサポートされていません。

Hibernateを使用すると、自分で名前を引用する必要があります。

@Entity
@Table(name="`Order`")
public class Order {
    ...
}

ドキュメントの関連セクションは次のとおりです。

5.4。 SQL引用識別子

マッピングドキュメントのバックティックでテーブルまたは列名を囲むことにより、生成されたSQLの識別子を引用させることができます。 Hibernateは、SQL方言の正しい引用スタイルを使用します。これは通常二重引用符ですが、SQLサーバーはブラケットを使用し、MySQLはバックティックを使用します。

<class name="LineItem" table="`Line Item`">
    <id name="id" column="`Item Id`"/><generator class="assigned"/></id>
    <property name="itemNumber" column="`Item #`"/>
    ...
</class>

参照

他のヒント

問題のもう1つのソリューションは、ここにあります: https://forum.hibernate.org/viewtopic.php?p=2409922

基本的に、必要なのは、テーブル名/列名を提供することに応じてクラスを導き出すことです。

それが助けてくれることを願っています。

乾杯、トゥルオン

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top