日期:2014-05-20  浏览次数:20807 次

List的removeAll方法异常?
现在正在实现的一个模块,是用Hibernate做的,一个用户对应多个频道,用的是一对多的关联,配置方件如下:
User表:
Java code

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
 <class lazy="false" name="com.autonavi.monitor.model.User" table="user">
  <id name="userId" type="integer" unsaved-value="0">
   <column name="userId"/>
   <generator class="native"/>
  </id>
  <property  name="name" type="string">
   <column name="name" />
  </property>
  <property  name="userName" type="string">
   <column name="userName" not-null="true"/>
  </property>
  <property name="password" type="string">
   <column name="password" not-null="true"/>
  </property>
  <property name="actor" type="int">
   <column name="actor"/>
  </property>
  <property name="authority" type="string">
   <column name="authority"/>
  </property>
  <property  name="email" type="string">
   <column name="email"/>
  </property>
  <property name="phone" type="string">
   <column name="phone"/>
  </property>
 <property name="phone1" type="string">
   <column name="phone1"/>
  </property>
  <property name="phone2" type="string">
   <column name="phone2"/>
  </property>
  
  <set name="channels" cascade="all" lazy="false">
      <key column="userId" />
      <one-to-many class="com.autonavi.monitor.model.Channel"/>
  </set>
  
 </class>
</hibernate-mapping>



频道表:
Java code

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
                                   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
 <class lazy="false" name="com.autonavi.monitor.model.Channel" table="channel">
  <id name="channelId" type="integer" unsaved-value="0">
   <column name="channelId"/>
   <generator class="native"/>
  </id>
  <property  name="channel" type="string">
   <column name="channel" />
  </property>
  <property  name="channelName" type="string">
   <column name="channel_name"/>
  </property>
  <property  name="delayTime" type="integer">
   <column name="delay_time" not-null="true"/>
  </property>
 </class>
</hibernate-mapping>


在Action里面做相应的查询,由于取消了懒加载,在查出的User里面会取到对应的频道列表
Java code

List<Channel> userChannelList = new ArrayList<Channel>();
            Channel channel = null;
            Set<Channel> channelSet = modifyUser.getChannels();
            Iterator<Channel> iterator = channelSet.iterator();
            while(iterator.hasNext()) {
                channel = (Channel)iterator.next();
                userChannelList.add(channel);
            }