hibernate3ではまった!第三弾。

はまりますねぇ。。。

schemaexportできない

私のプロジェクトでは、スキーマ作成用のantタスクを定義しているのですが、そいつがちゃんと動きません。こんなエラーメッセージ。

Schema text failed: An AnnotationConfiguration instance is required to use 略

しかも冒頭にはこんなメッセージも出ています。

This is an Ant task supporting only mapping files, if you want to use annotations see http://tools.hibernate.org.

またアノテーションかよ!うんざりするぜ!!
・・・おっと失礼。どうやらhbm.xmlファイルを読み込んでスキーマエクスポートする時はいいけど、アノテーションつかった場合はこれではいけないってことらしい。

参考までに今までのbuild.xmlの定義です。

<taskdef name="schemaexport" classname="org.hibernate.tool.hbm2ddl.SchemaExportTask" >
	<classpath refid="build.classpath" />
</taskdef>
<schemaexport config="${src.dir}/hibernate.cfg.xml" properties="${src.dir}/hibernate.properties" quiet="no" text="no" drop="no" delimiter=";"  output="schema-export.sql">
</schemaexport>

解決策

  1. hibernate toolsをダウンロードする。
  2. 解凍後、HibernateTools-3.2.0.beta10/plugins/org.hibernate.eclipse_3.2.0.beta10/lib/toolsにあるhibernate-tools.jarをクラスパスに追加する。
  3. build.xmlを以下のように書き換える。
<taskdef name="schemaexport" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="build.classpath"/> 

<schemaexport destdir="./"> 
	<annotationconfiguration configurationfile="${src.dir}/hibernate.cfg.xml"/>
	<hbm2ddl drop="true"/>
</schemaexport>

これで終わりです。なんかめちゃめちゃ変わってますよね。疲れた。。