您需要
fetch=FetchType.EAGER在ManyToMany批注中添加以自动拉回子实体:
@ManyToMany(fetch = FetchType.EAGER)
更好的选择是通过将以下内容添加到您的spring配置文件中来实现spring transactionManager:
<bean id="transactionManager" > <property name="sessionFactory" ref="sessionFactory" /></bean><tx:annotation-driven />
然后可以将@Transactional批注添加到您的authenticate方法中,如下所示:
@Transactionalpublic Authentication authenticate(Authentication authentication)
然后,这将在authenticate方法期间启动db事务,从而允许在尝试使用它们时从db中检索任何惰性集合。



