第一个问题。为什么我的MyEclipse for Spring 8.6
只要一点左边的Package Explorer就会卡死了!要等n秒,然后再点又卡住了!
我照着网上的夜优化了!
可就是点击Package Explorer那个列表就会卡死!特别是点xml文件
可是只要把网线断了就又没有问题了!我的机器是2g内存.
请问怎么才能解决啊?还有一个问题
可能是我能力问题吧!我感到莫名其妙开始我先试了下级联删除,没问题
如下Testa的映射文件<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="zengxiaodong.pojo">
<class name="Testa" table="testa" lazy="true"> <id name="id" column="id" type="long">
<generator class="increment"/>
</id> <property name="tname" column="tname" not-null="true" length="20" type="string"/>
<set name="items" inverse="true" lazy="true" cascade="all,delete-orphan">
<key column="testa_id" />
<one-to-many class="zengxiaodong.pojo.Testb" />
</set>
</class>

</hibernate-mapping>
Testb的映射文件<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="zengxiaodong.pojo">
<class name="Testb" table="testb" lazy="true"> <id name="id" column="id" type="long">
<generator class="increment"/>
</id>
<many-to-one name="testa" column="testa_id" class="zengxiaodong.pojo.Testa" cascade="none" fetch="join"/>
<property name="tname" column="tname" not-null="true" length="20" type="string"/>

</class>

</hibernate-mapping>
然后我就删除this.getTestaMrg().delete(this.getTestaMrg().get(1));没问题。把Testa和他的Testb都一起删除了!可是我接下来照着做,怎么又不行呢?高手帮我看看
一个是use对象里面有很有address对象
我删除use对象老是抛出异常。

org.hibernate.exception.GenericJDBCException:could not initialize a collection[zengxiaoidong.pojo.User.myAddresses#4]可我进行的是删除操作。我记得hibernate的延迟加载是在获取对象的时候才对多的一方生成一个代理对象,并没有填充
可我现在是在删除,怎么会出现这样的情况的?========删除===========================
User u=this.getUserMrg().get(1);
this.getUserMrg().delete(u);在数据库中已经有对应的记录
并且在spring文件中定义了事务
=====================================public class User {
private long id;
private String userName;
private String passWord;
private String email;
private Date  createDate;
private Set<MyAddress> myAddresses=new HashSet<MyAddress>();
public Set<MyAddress> getMyAddresses() {
return myAddresses;
}
public void setMyAddresses(Set<MyAddress> myAddresses) {
this.myAddresses = myAddresses;
}
}public class MyAddress{ private long id;
private String recName;
private String handTel;
private String homeTel;
private String addre;
private String code;
private Date createDate;
private User user; public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
。}User映射文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="zengxiaodong.pojo">
<class name="User" table="user" lazy="true"> <id name="id" column="id" type="long">
<generator class="increment"/>
</id> <property name="userName" column="userName" not-null="true" length="50" type="string"/>
<property name="passWord" column="passWord" not-null="true" length="255" type="string"/>
<property name="email" column="email" not-null="true" length="100" type="string"/>
<property name="createDate" column="createDate" type="timestamp"/>
<set name="myAddresses" inverse="true" lazy="true" cascade="all,delete-orphan">
<key column="userId" />
<one-to-many class="zengxiaodong.pojo.MyAddress" />
</set>
</class>

</hibernate-mapping>
MyAddress映射文件<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="zengxiaodong.pojo">
<class name="MyAddress" table="myaddress"> <id name="id" column="id" type="long">
<generator class="increment"/>
</id> <property name="recName" column="recName" not-null="true" length="50" type="string"/>
<property name="handTel" column="handTel" not-null="true" length="30" type="string"/>
<property name="homeTel" column="homeTel" not-null="true" length="30" type="string"/>
<property name="createDate" column="createDate" type="timestamp"/>
<property name="addre" column="addre" not-null="true" length="255" type="string"/>
<property name="code" column="code" not-null="true" length="12" type="string"/>
<many-to-one name="user" column="userId" class="zengxiaodong.pojo.User" cascade="none" fetch="join"/>
</class>
</hibernate-mapping>在spring中的定义<!-- 数据源连接池对象  --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/shop?useUnicode=true&amp;characterEncoding=gb2312"/>
<property name="user" value="root"/>
<property name="password" value="root"/>
<property name="maxPoolSize" value="20"/>
<property name="initialPoolSize" value="1"/>
<property name="maxIdleTime" value="20"/>
</bean>    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mappingResources">
            <list>
             <value>MyAddress.hbm.xml</value>
             <value>Admin.hbm.xml</value>
<value>AdminUpdataList.hbm.xml</value>
<value>Cog.hbm.xml</value>
<value>Colors.hbm.xml</value>
<value>IndexPage.hbm.xml</value>
<value>IndexZhuanTi.hbm.xml</value>
<value>Item.hbm.xml</value>
<value>ItemChildren.hbm.xml</value>
<value>MessageBook.hbm.xml</value>
<value>MessageBookReply.hbm.xml</value>
<value>Produce.hbm.xml</value>
<value>ProduceBook.hbm.xml</value>
<value>ProduceBookReply.hbm.xml</value>
<value>ProduceHeadImage.hbm.xml</value>
<value>ProduceMessage.hbm.xml</value>
<value>ProduceMessageReply.hbm.xml</value>
<value>Sizes.hbm.xml</value>
<value>User.hbm.xml</value>
<value>YunFei.hbm.xml</value>
<value>ProduceStart.hbm.xml</value>
<value>UserOrder.hbm.xml</value>
<value>UserOrderItem.hbm.xml</value>
<value>Testa.hbm.xml</value>
<value>Testb.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="show_sql">true</prop>
                <prop key="hibernate.jdbc.batch_size">20</prop> 
            </props>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <!--  事务拦截器bean需要依赖注入一个事务管理器 -->
        <property name="transactionManager" ref="transactionManager"/>
     <property name="transactionAttributes">
    <!--  下面定义事务传播属性-->
    <props>
    <prop key="get*">readOnly</prop>
    <prop key="find*">readOnly</prop>
     <prop key="add*">PROPAGATION_REQUIRED</prop>
     <prop key="up*">PROPAGATION_REQUIRED</prop>
     <prop key="delete">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
</bean>    <!-- 定义BeanNameAutoProxyCreator-->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <!--  指定对满足哪些bean name的bean自动生成业务代理 -->
    <property name="beanNames">
            <!--  下面是所有需要自动创建事务代理的bean-->
            <list>
                <value>userMrg</value>
              
                
            </list>
            <!--  此处可增加其他需要自动创建事务代理的bean-->
    </property>
        <!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
        <property name="interceptorNames">
            <list>
                <!-- 此处可增加其他新的Interceptor -->
                <value>transactionInterceptor</value> 
            </list>
        </property>
    </bean>

解决方案 »

  1.   

    首先要谢谢你
    下面是hibernate里面的映射文件
    一对多双向
    可是我删除1这边的对象出现异常org.hibernate.exception.GenericJDBCException:could not initialize a collection[zengxiaoidong.pojo.User.myAddresses#4]请帮我看看配置文件哪里错了?我实在是找不到错在哪里了
    User.hbm.xml
    //=============================================
    <set name="myAddresses" inverse="true" lazy="true" cascade="all,delete-orphan">
    <key column="userId" />
    <one-to-many class="zengxiaodong.pojo.MyAddress" />
    </set>
    //====================================================
    MyAddress.hbm.xml
    <many-to-one name="user" column="userId" class="zengxiaodong.pojo.User" cascade="none" fetch="join"/>
    </class> 
      

  2.   

    <set name="myAddresses" inverse="true" lazy="true" cascade="all,delete-orphan">
    <key column="userId" />
    将inverse="true"  设为false