Hibernate3 父子映射报错: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
)
在做父子映射时候,使用父类去获取子类时候,报错如上。
跟踪栈信息,我们可以发现,domain object的 hashCode 方法有错误。
原来的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
* 继承此类可以自动获得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()
{}
;
}
但是除去该基类后,发现错误被修复了。
暂时还不清楚问题为什么会发生。
posted on 2006-10-16 09:29
旱头憨脑
阅读(6160)
评论(1)
编辑
收藏
评论
#
re: Hibernate3 父子映射报错:illegal access to loading collection
2007-12-19 14:44
d
回复
更多评论
原因在与pojo里面的 public int hashCode() {... } 方法调用了set对象成员的hashCode()方法
如this.getSets().hashCode();
删除该方法的调用即可;调用非set对象成员的.hashCode()方法没有问题。
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
知识库
C++博客
博问
管理
旱头憨脑
lanluquan
导航
BlogJava
首页
新随笔
联系
聚合
管理
统计
随笔 - 1
文章 - 10
评论 - 1
引用 - 0
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
■
2006年10月 (1)
文章分类
■
ajax(1)
(rss)
■
j2ee(7)
(rss)
■
java
(rss)
■
ruby(1)
(rss)
■
非技术(1)
(rss)
文章档案
■
2008年6月 (1)
■
2007年9月 (1)
■
2007年7月 (1)
■
2006年10月 (4)
■
2006年9月 (1)
■
2006年8月 (2)
搜索
最新评论
1. re: Hibernate3 父子映射报错:illegal access to loading collection
评论内容较长,点击标题查看
--d