OpenSessionInViewFilterを使用しています。これは私のweb.xmlの最初のフィルターです
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
これが私のapplicationContext.xmlの一部です
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="userBc" class="com.tutorial.bc.auth.UserBcImpl">
<property name="userDao">
<ref local="userDao"/>
</property>
</bean>
...
<tx:annotation-driven transaction-manager="txManager"/>
hbmファイルでの私のマッピング-
<set name="userCoachingRoles" table="user_coaching_role" lazy="true" cascade="all-delete-orphan">
<key column="user_id"/>
<many-to-many column="coaching_id" class="com.tutorial.entity.coaching.Coaching" lazy="proxy"/>
</set>
ユーザーを取得するuserBcのメソッドには注釈が付けられ@Transactional
、エンティティUserにはメソッドがありgetUserCoachingRoles
ます。このメソッドにヒットする例外が発生します-
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
を使用してもセッションがない理由がわかりませんOpenSessionInViewFilter
。これについて助けが必要です。