hibernate annotations を試す


↓の記事を参考にhibernate annotations を試しました

Hibernate Annotations アノテーションを使った効率の良いHibernate開発
http://634.ayumu-baby.com/hibernate-annotations.html

実行したら、↓のエラーになりました


SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6, 1.5.7, 1.5.8]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
10 13, 2012 9:11:18 午前 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.7.Final}
10 13, 2012 9:11:18 午前 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
10 13, 2012 9:11:18 午前 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
at java.lang.ClassLoader.defineClass1(Native Method)
(~省略~)

早速、"org/hibernate/util/DTDEntityResolver" でぐぐったところ

↓の投稿に引っかかりました

http://stackoverflow.com/questions/9134436/how-can-i-resolve-java-lang-classnotfoundexception-org-hibernate-util-dtdentity

どうやらエラー原因は hibernate-annotations のバージョンに、
他の hibernate のライブラリがあっていないためのようです
自分の環境では↓でした

hibernate-annotations 3.5.6-Final
hibernate-core 4.1.7.Final
hibernate-entitymanager 4.1.7.Final

それを↓のように変更し、ライブラリの更新
(パッケージエクスプローラからプロジェクトを右クリックし、コンテキストメニューからMaven→Update)(参考の記事から引用)
しました

hibernate-annotations 3.5.6-Final
hibernate-core 3.5.6-Final
hibernate-entitymanager 3.5.6-Final

↓の記事にある

Hibernate Annotations を使い始めるときにハマったこと
http://d.hatena.ne.jp/keigoi/20071122/1195749848

hibernate.cfg.xml をどこに置いて良いのかわからなかった」に
自分もなりました

具体的には↓のディレクトリに置きました
/com.example.hibernate.annotations/src/main/java

なんとか動きました


Hibernate: select this_.id as id0_0_, this_.name as name0_0_ from EMP this_
たろう
じろう