私は使用してSpring 4.2.1
おりHiberante 5
、Spring Bean 定義で宣言されたセッションを次のように春が初期化する方法を理解しようとしています。
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- properties -->
</bean>
いわゆるorg.springframework.orm.hibernate5.LocalSessionFactoryBeanが実装されていることがわかりましたFactoryBean<SessionFactory>
。これを考慮に入れるSessionFactory
と、定義をクラスに注入するように定義しているorg.springframework.orm.hibernate5.LocalSessionFactoryBean
のに、最終的に のインスタンスになってしまう理由は明らかですSessionFactory
。さて、私が混乱したのはメソッドgetCurrentSessionです:
public Session getCurrentSession() throws HibernateException {
if ( currentSessionContext == null ) {
throw new HibernateException( "No CurrentSessionContext configured!" );
}
return currentSessionContext.currentSession();
}
これは、実際のセッション作成をSpringSessionContextに委任します。私の場合、このコードによって取得されています。
SessionHolder sessionHolder = (SessionHolder) value;
Session session = sessionHolder.getSession();
しかし、session
実際には、それ自体がプロパティprotected transient SessionFactoryImpl factoryorg.hibernate.internal.SessionImpl
を持つ直接基本クラスのインスタンスです。org.hibernate.internal.AbstractSessionImpl
したがって、私の場合は実際のインスタンスを保持SessionFactory
するCurrentSessionContext
プロパティがあります。しかし、再びタイプのプロパティがあります。SessionHolder
Session
SessionImpl
SessionFactory
循環が理解できません。ちょっと説明していただけませんか。