daybreaksnow's diary

私を私と呼びたい

Hibernate触る

環境

 hibernate-3.5.2-Final-dist.zipを解凍し、hibernate3.jarとrequired以下のjarをビルドパスに追加。postgreのJDBCドライバも追加。

 

hibernate.hbm.cfg、テーブル、hbm、POJOを作り以下のサンプルコードで実行

 

 

public static void main(String[] args) {

Configuration config = new Configuration().configure();

SessionFactory sessionFactory = config.buildSessionFactory();

Session session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();

Item item = new Item();

item.setName("hoge");

session.save(item);

tx.commit();

session.close();

}

 

 

結果、以下の例外が発生した。

 

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

 

 

SLF4Jに対応するロガーがないようなので、以下のサイトから対応するバージョンのものをダウンロード。(hibernate-3.5.2ではSLF4Jは1.5.8)

http://www.slf4j.org/dist/

ダウンロードしたzipの中のslf4j-nop-1.5.8.jarをビルドパスに通すことで、実行できるようになった。

 

nopはどうかと思ったので、log4jとslf4j-log4j12-1.5.8.jarを使っても出来た。

log4J:http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip