These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: It seems that the lazy="true" don't useful in Hibe
PostPosted: Thu Jul 13, 2006 11:23 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
When i developing with Hibernate2.x,i must manually add lazy=true in hbm.xml,for example:

<class ....... lazy="true">
</class>

There are 2 classes C and P and the relation between C and P is many-to-one.

hql is "from C".

when lazy="false",the original sqls presented in console are:
select c.id,c.name from c
select p.id,p.name from p where p.id=?

when lazy="true" sql is:
select c.id,c.name from c

But in Hibernate3.x,i don't need add lazy=true in hbm.xml,because it is the default behaviour,but it seems not useful.

whether lazy is true or false,the sqls always are:
select c.id,c.name from c
select p.id,p.name from p where p.id=?

why?Can anybody tell me the cause?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 13, 2006 11:58 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Depends on which version of Hibernate 3 you're talking about, and which lazy attribute (they're slightly different, depending on if you're talking about classes, associations or collections). There have been a few changes in this area during the lifetime of the Hibernate3 project.

For a many-to-one association, the default state (whether your class is lazy="true" or lazy="false") is lazy="proxy", and that seems to need to issue a select statement (though I have no idea why). You need to specify lazy="no-proxy" on the association to avoid the select.

In the ref docs, section 19.1.3, "Single-ended association proxies", explains all this.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Hi
PostPosted: Fri Jul 14, 2006 2:10 am 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
Thank you for your help.

as your said,for
<many-to-one class="" />
lazy="proxy" is default.

but when i execute the hql

"from C"

The follow exceptions are thrown:


Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:99)
at org.hibernate.proxy.CGLIBProxyFactory.getProxy(CGLIBProxyFactory.java:47)
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3120)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:812)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:782)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.amjn.web.dao.hibernate.user.admin.AdminRoleResourceDAO.remove(AdminRoleResourceDAO.java:30)
at com.amjn.web.bo.user.admin.AdminRoleResourceBO.remove(AdminRoleResourceBO.java:16)
at com.amjn.web.bp.user.admin.AdminRoleResourceBP.clearAndCreate(AdminRoleResourceBP.java:34)
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:324)
at com.amjn.web.util.sql.DBInvocationHandler.invoke(DBInvocationHandler.java:20)
at $Proxy3.clearAndCreate(Unknown Source)
at com.amjn.web.struts.action.admin.user.admin.ARoleResourceAdminAction.reCreate(ARoleResourceAdminAction.java:63)
... 41 more
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236)
at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:64)
at net.sf.cglib.proxy.MethodProxy.helper(MethodProxy.java:81)
at net.sf.cglib.proxy.MethodProxy.create(MethodProxy.java:46)
at com.amjn.web.model.user.admin.AdminRoleModel$$EnhancerByCGLIB$$7033e790.CGLIB$STATICHOOK2(<generated>)
at com.amjn.web.model.user.admin.AdminRoleModel$$EnhancerByCGLIB$$7033e790.<clinit>(<generated>)
... 80 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor84.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218)
... 85 more
Caused by: java.lang.LinkageError: duplicate class definition: $java/lang/Object$$FastClassByCGLIB$$3f697993
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)


Top
 Profile  
 
 Post subject: Hi
PostPosted: Fri Jul 14, 2006 2:11 am 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
Thank you for your help.

as your said,for
<many-to-one class="" />
lazy="proxy" is default.

but when i execute the hql

"from C"

The follow exceptions are thrown:


Caused by: java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:308)
at java.lang.Class.newInstance(Class.java:261)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:99)
at org.hibernate.proxy.CGLIBProxyFactory.getProxy(CGLIBProxyFactory.java:47)
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3120)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:812)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:782)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:223)
at org.hibernate.loader.Loader.doList(Loader.java:2147)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2026)
at org.hibernate.loader.Loader.list(Loader.java:2021)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:298)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:137)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1014)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.amjn.web.dao.hibernate.user.admin.AdminRoleResourceDAO.remove(AdminRoleResourceDAO.java:30)
at com.amjn.web.bo.user.admin.AdminRoleResourceBO.remove(AdminRoleResourceBO.java:16)
at com.amjn.web.bp.user.admin.AdminRoleResourceBP.clearAndCreate(AdminRoleResourceBP.java:34)
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:324)
at com.amjn.web.util.sql.DBInvocationHandler.invoke(DBInvocationHandler.java:20)
at $Proxy3.clearAndCreate(Unknown Source)
at com.amjn.web.struts.action.admin.user.admin.ARoleResourceAdminAction.reCreate(ARoleResourceAdminAction.java:63)
... 41 more
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236)
at net.sf.cglib.reflect.FastClass$Generator.create(FastClass.java:64)
at net.sf.cglib.proxy.MethodProxy.helper(MethodProxy.java:81)
at net.sf.cglib.proxy.MethodProxy.create(MethodProxy.java:46)
at com.amjn.web.model.user.admin.AdminRoleModel$$EnhancerByCGLIB$$7033e790.CGLIB$STATICHOOK2(<generated>)
at com.amjn.web.model.user.admin.AdminRoleModel$$EnhancerByCGLIB$$7033e790.<clinit>(<generated>)
... 80 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor84.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218)
... 85 more
Caused by: java.lang.LinkageError: duplicate class definition: $java/lang/Object$$FastClassByCGLIB$$3f697993
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)

I must set lazy="false"
<many-to-one class="..." lazy="false"/>
It works.

why?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 5:41 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
LinkageError? Wow, don't see those very often. At a guess, I'd say that you have two mappings to the same class without an entity-name to distinguish them. And by the looks of the error, the class that you've mapped is Object. So I guess I can't tell much from the error :)

Inspect the mappings for AdminRoleModel: make sure that it isn't mapped more than once, and that it's not referring to proxied associations from its constructor. Also check the constructors of other classes to make sure that nothing else is referring to a proxied AdminRoleModel. Something like that is going on.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 5:42 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
LinkageError? Wow, don't see those very often. At a guess, I'd say that you have two mappings to the same class without an entity-name to distinguish them. And by the looks of the error, the class that you've mapped is Object. So I guess I can't tell much from the error :)

Inspect the mappings for AdminRoleModel: make sure that it isn't mapped more than once, and that it's not referring to proxied associations from its constructor. Also check the constructors of other classes to make sure that nothing else is referring to a proxied AdminRoleModel. Something like that is going on.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: The problem has been resolved.
PostPosted: Tue Jul 18, 2006 10:05 pm 
Regular
Regular

Joined: Fri Nov 12, 2004 12:07 am
Posts: 57
Location: Beijing,China
Hi tenwit,


Very appreciate for your help.I think i have been resolved this problem,the error didn't present since i replaced proxool0.9.RC with proxool-0.8.3.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.