ERROR LazyInitializationException:42 - failed to lazily initialize a collection of role: com.lixueli.business.model.Person.events, no session or session was closed
在配置文件中加入lazy="false"即可
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.lixueli.business.model.Person" table="person"> <id name="id" column="PERSON_ID"> <generator class="native"></generator> </id> <property name="age"></property> <property name="firstName"></property> <property name="lastName"></property> <set name="events" table="PERSON_EVENT" lazy="false"> <key column="PERSON_ID"></key> <many-to-many column="EVENT_ID" class="com.lixueli.business.model.Event"></many-to-many> </set> </class> </hibernate-mapping>