<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Hibernate3 父子映射報(bào)錯(cuò):illegal access to loading collection


    org.springframework.orm.hibernate3.HibernateSystemException:?illegal?access?to?loading?collection;?nested?exception?is?org.hibernate.LazyInitializationException:?illegal?access?to?loading?collection
    Caused?by:?org.hibernate.LazyInitializationException:?illegal?access?to?loading?collection
    ????at?org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:
    341 )
    ????at?org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:
    86 )
    ????at?org.hibernate.collection.PersistentSet.hashCode(PersistentSet.java:
    355 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:
    348 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:
    309 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:
    283 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:
    150 )
    ????at?com.hiany.forum.domain.base.BaseObject.hashCode(BaseObject.java:
    32 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.append(HashCodeBuilder.java:
    348 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.reflectionAppend(HashCodeBuilder.java:
    309 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:
    283 )
    ????at?org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode(HashCodeBuilder.java:
    150 )
    ????at?com.hiany.forum.domain.base.BaseObject.hashCode(BaseObject.java:
    32 )
    ????at?java.util.HashMap.hash(HashMap.java:
    264 )
    ????at?java.util.HashMap.put(HashMap.java:
    382 )
    ????at?java.util.HashSet.add(HashSet.java:
    194 )
    ????at?java.util.AbstractCollection.addAll(AbstractCollection.java:
    318 )
    ????at?org.hibernate.collection.PersistentSet.endRead(PersistentSet.java:
    273 )
    ????at?org.hibernate.engine.CollectionLoadContext.endLoadingCollection(CollectionLoadContext.java:
    183 )
    ????at?org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:
    268 )
    ????at?org.hibernate.engine.CollectionLoadContext.endLoadingCollections(CollectionLoadContext.java:
    249 )
    ????at?org.hibernate.loader.Loader.endCollectionLoad(Loader.java:
    866 )
    ????at?org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:
    853 )
    ????at?org.hibernate.loader.Loader.doQuery(Loader.java:
    717 )
    ????at?org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:
    224 )
    ????at?org.hibernate.loader.Loader.loadCollection(Loader.java:
    1919 )
    ????at?org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:
    36 )
    ????at?org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:
    520 )
    ????at?org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:
    60 )
    ????at?org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:
    1676 )
    ????at?org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:
    454 )
    ????at?org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:
    755 )
    ????at?org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:
    229 )
    ????at?org.hibernate.loader.Loader.loadEntity(Loader.java:
    1785 )
    ????at?org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:
    47 )
    ????at?org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:
    41 )
    ????at?org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:
    2730 )
    ????at?org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:
    365 )
    ????at?org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:
    346 )
    ????at?org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:
    123 )
    ????at?org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:
    177 )
    ????at?org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:
    87 )
    ????at?org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:
    862 )
    ????at?org.hibernate.impl.SessionImpl.get(SessionImpl.java:
    799 )
    ????at?org.hibernate.impl.SessionImpl.get(SessionImpl.java:
    792 )
    ????at?org.springframework.orm.hibernate3.HibernateTemplate$
    1 .doInHibernate(HibernateTemplate.java: 460 )
    ????at?org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:
    362 )
    ????at?org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:
    454 )
    ????at?org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTemplate.java:
    448 )
    ????at?com.hiany.forum.dao.HibernateGenericDao.get(HibernateGenericDao.java:
    41 )
    ????at?com.hiany.forum.dao.HibernateEntityDao.get(HibernateEntityDao.java:
    40 )
    ????at?com.hiany.forum.dao.HibernateEntityDao$$FastClassByCGLIB$$967b2136.invoke(
    < generated > )
    ????at?net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:
    149 )
    ????at?org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:
    714 )
    ????at?org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    162 )
    ????at?org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:
    107 )
    ????at?org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:
    185 )
    ????at?org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:
    652 )
    ????at?com.hiany.forum.service.ArticleManager$$EnhancerByCGLIB$$64259eef.get(
    < generated > )
    ????at?com.hiany.forum.service.ArticleManageTest.testArticleManager(ArticleManageTest.java:
    56 )
    ????at?sun.reflect.NativeMethodAccessorImpl.invoke0(Native?Method)
    ????at?sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    39 )
    ????at?sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    25 )
    ????at?java.lang.reflect.Method.invoke(Method.java:
    585 )
    ????at?junit.framework.TestCase.runTest(TestCase.java:
    154 )
    ????at?junit.framework.TestCase.runBare(TestCase.java:
    127 )
    ????at?org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:
    69 )
    ????at?junit.framework.TestResult$
    1 .protect(TestResult.java: 106 )
    ????at?junit.framework.TestResult.runProtected(TestResult.java:
    124 )
    ????at?junit.framework.TestResult.run(TestResult.java:
    109 )
    ????at?junit.framework.TestCase.run(TestCase.java:
    118 )
    ????at?junit.framework.TestSuite.runTest(TestSuite.java:
    208 )
    ????at?junit.framework.TestSuite.run(TestSuite.java:
    203 )
    ????at?org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:
    128 )
    ????at?org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
    38 )
    ????at?org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
    460 )
    ????at?org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:
    673 )
    ????at?org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:
    386 )
    ????at?org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:
    196 )
    在做父子映射時(shí)候,使用父類去獲取子類時(shí)候,報(bào)錯(cuò)如上。
    跟蹤棧信息,我們可以發(fā)現(xiàn),domain object的 hashCode 方法有錯(cuò)誤。
    原來(lái)的domain object 使用了BaseObject作為基類:

    import?org.apache.commons.lang.builder.EqualsBuilder;
    import?org.apache.commons.lang.builder.HashCodeBuilder;
    import?org.apache.commons.lang.builder.ToStringBuilder;
    import?org.apache.commons.lang.builder.ToStringStyle;

    import?java.io.Serializable;

    /**
    ?*?基類,domain?object?
    ?*?繼承此類可以自動(dòng)獲得toString?equals?hashCode的method。
    ?
    */

    public?abstract?class?BaseObject?implements?Serializable?{
    ????
    private?static?final?long?serialVersionUID?=?3256446889040622647L;

    ????
    public?String?toString()?{
    ????????
    return?ToStringBuilder.reflectionToString(this,
    ????????????????ToStringStyle.MULTI_LINE_STYLE);
    ????}


    ????
    public?boolean?equals(Object?o)?{
    ????????
    return?EqualsBuilder.reflectionEquals(this,?o);
    ????}


    ????
    public?int?hashCode()?{
    ????????
    return?HashCodeBuilder.reflectionHashCode(this);
    ????}

    ????
    ????
    protected?void?init(){};
    }

    但是除去該基類后,發(fā)現(xiàn)錯(cuò)誤被修復(fù)了。
    暫時(shí)還不清楚問(wèn)題為什么會(huì)發(fā)生。
    posted on 2006-10-16 09:29 旱頭憨腦 閱讀(6177) 評(píng)論(1)  編輯  收藏

    評(píng)論

    # re: Hibernate3 父子映射報(bào)錯(cuò):illegal access to loading collection 2007-12-19 14:44 d  回復(fù)  更多評(píng)論   

    原因在與pojo里面的 public int hashCode() {... } 方法調(diào)用了set對(duì)象成員的hashCode()方法
    如this.getSets().hashCode();
    刪除該方法的調(diào)用即可;調(diào)用非set對(duì)象成員的.hashCode()方法沒(méi)有問(wèn)題。

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 美女露隐私全部免费直播| 成人毛片免费视频| 日本系列1页亚洲系列| 亚洲男女一区二区三区| 亚洲无码在线播放| 免费一级黄色毛片| 好爽…又高潮了毛片免费看| 免费无码一区二区三区| 不卡视频免费在线观看| 国产亚洲精品精品精品| 亚洲精品一二三区| 亚洲国产成人综合| 亚洲高清无在码在线无弹窗| 亚洲国产另类久久久精品| 久久激情亚洲精品无码?V| 又粗又大又猛又爽免费视频| 成年女人毛片免费播放人| 国产一卡2卡3卡4卡无卡免费视频| 免费一级不卡毛片| 中文成人久久久久影院免费观看| 草久免费在线观看网站| 曰批视频免费40分钟试看天天 | 男人j进入女人j内部免费网站| 亚洲avav天堂av在线网毛片| 亚洲日本乱码卡2卡3卡新区| 亚洲精品不卡视频| 亚洲精品免费在线视频| 亚洲激情视频网站| 亚洲成人黄色网址| 亚洲中文字幕久在线| 亚洲伊人久久大香线焦| 精品亚洲AV无码一区二区三区| 亚洲成aⅴ人片在线影院八| 亚洲国产成人91精品| 亚洲一区二区三区四区视频| 久久精品国产99国产精品亚洲| 亚洲视频一区二区三区四区| 亚洲午夜一区二区三区| 亚洲成a人片在线不卡一二三区| 亚洲AV无码一区二区乱子仑 | 巨胸喷奶水视频www网免费|