org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: hospital.model.Role.roleAuths, no session or session was closed
这个主要是由于懒加载引起的,在相应的配置文件中添加lazy="false"就可以了。
比如: <set name="userRoles" inverse="true" lazy="false">
<key>
<column name="roleid" not-null="true" />
</key>
<one-to-many class="hospital.model.UserRole" />
</set>
<set name="roleAuths" inverse="true" lazy="false">
<key>
<column name="roleid" not-null="true" />
</key>
<one-to-many class="hospital.model.RoleAuth" />
</set>