// 下階層用テンプレート
#topicpath
----
//ここにコンテンツを記述します。

Hibernateには[[org.hibernate.Interceptor>http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Interceptor.html]]というCallBackのためのインタフェースがありますが、このインタフェース(の実装クラス)はSessionに対してセットすることになっています。

さて、Springを使ってるとSessionとかでてこねーよなーどこでセットするのかなあと[[SpringのJavaDoc>http://www.springframework.org/docs/api/index.html]]をあさっていたところ[[org.springframework.orm.hibernate3.LocalSessionFactoryBean>http://www.springframework.org/docs/api/org/springframework/orm/hibernate3/LocalSessionFactoryBean.html#setEntityInterceptor(org.hibernate.Interceptor)]]に、
 public void setEntityInterceptor(Interceptor entityInterceptor)
というメソッドがありました。これを使えば良さそうです。またこのクラスはSpring&Hibernateでよく出てくる sessionFactoryのクラスなので、たとえば
 </bean>
   <bean id="sessionFactory" 
   class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
   <property name="dataSource">
     <ref local="dataSource" />
   </property>
   <property name="mappingResources">
     <list>
       <value>nu/mine/kino/entity/webdb1/Item.hbm.xml</value>
       <value>nu/mine/kino/entity/webdb1/Bid.hbm.xml</value>
     </list>
   </property>
   <property name="hibernateProperties">
     <props>
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
     </props>
   </property>
   <property name="entityInterceptor"> <-これ
     <ref bean="entityInterceptor" />
   </property>
 </bean>
というようにInjectionすればOKです。あとはこのInterceptorインタフェースの実装クラスを作ればOK!.


----
この記事は
#vote(おもしろかった[6],そうでもない[3])
#vote(おもしろかった[7],そうでもない[3])

#comment
#topicpath


SIZE(10){現在のアクセス:&counter;}

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS