-->
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.  [ 5 posts ] 
Author Message
 Post subject: Query throws exception: need interface mappings?
PostPosted: Thu Sep 29, 2005 4:59 pm 
Newbie

Joined: Thu Sep 22, 2005 7:09 pm
Posts: 14
I have a simple query, "select r from ReleaseBO r where r.name = 'x' and r.project.name = 'y'", which is throwing a HibernateSystemException,
'CGLIB Enhancement failed' (see below).

The only thing I can think of is that the 'project' property is declared as an interface type and my Hibernate mappings are all for the concrete implementation classes. I suspect Hibernate is trying to enhance and instantiate the interface type. Does that sound likely?

If so, how do I tell Hibernate to use the implementation type when it encounters a reference to an interface in a persistent class? My first thought was to supply mapping files for the interfaces as well as the implementing classes, but I couldn't see how to make that work without having both getter and setter methods defined on the interface for every property, which isn't acceptable.

Of course, the exception may mean something else entirely, it's not exactly obvious what the underlying problem is ;-) So, am I diagnosing it correctly? And how do I solve the problem?

L.

org.springframework.orm.hibernate3.HibernateSystemException: CGLIB Enhancement failed: com.foo.projility.modules.project.domain.ProjectBO; nested exception is org.hibernate.HibernateException: CGLIB Enhancement failed: com.foo.projility.modules.project.domain.ProjectBO
org.hibernate.HibernateException: CGLIB Enhancement failed: com.foo.projility.modules.project.domain.ProjectBO
at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:80)
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:3103)
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:781)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:753)
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:296)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:992)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:751)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:742)
at com.foo.projility.domain.BaseDAOHib.load(BaseDAOHib.java:140)
at com.foo.projility.domain.BaseDAOHib.load(BaseDAOHib.java:128)
at com.foo.projility.modules.project.domain.ReleaseDAOHib.loadRelease(ReleaseDAOHib.java:49)
at com.foo.projility.modules.project.domain.ReleaseDAOTest.testLoadReleaseBase(ReleaseDAOTest.java:124)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
Caused by: java.lang.InstantiationException: com.foo.projility.modules.project.domain.ProjectBO$$EnhancerByCGLIB$$ef4c2bbe
at java.lang.Class.newInstance0(Class.java:335)
at java.lang.Class.newInstance(Class.java:303)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:77)
... 46 more

_________________
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 5:18 pm 
Senior
Senior

Joined: Tue Feb 08, 2005 5:26 pm
Posts: 157
Location: Montréal, Québec - Canada
Hi Laurie,

I think you have identified the problem correctly.

There might be a better answer than mine, but my understanding is: If you have a class ReleaseBoImpl that has a relationship to a Project interface, mapping has to be done on concrete classes, but your java class can work on the interface:

Code:
public class ReleaseBoImpl implements ReleaseBo
{
private Project project;
//getter setters etc.
}

public class ProjectImpl implements Project
{
}


You mapping should be done on your concrete classes:
Quote:
ReleaseBo.hbm.xml:
<class name="ReleaseBoImpl" table="ReleaseBO">
<many-to-one name="project" class="ProjectImpl"

Project.hbm.xml:
<class name="ProjectImpl" table="Project">


You can still implement inheritance etc.

I hope that helps you.

_________________
Vincent Giguère
J2EE Developer


Top
 Profile  
 
 Post subject: That's basically what I have
PostPosted: Fri Sep 30, 2005 6:11 pm 
Newbie

Joined: Thu Sep 22, 2005 7:09 pm
Posts: 14
Yes, that's basically what I have; the mappings are written to the implementation classes. I even have class="ProjectBoImpl" in the mapping data for the 'project' field, so Hibernate should be able to find the class rather than the interface... Still get the excetpion though :(

_________________
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


Top
 Profile  
 
 Post subject: Any other suggestions?
PostPosted: Sun Oct 02, 2005 4:04 pm 
Newbie

Joined: Thu Sep 22, 2005 7:09 pm
Posts: 14
Does anyone have any other suggestions on what's wrong here, or how to fix it?

Thanks,

L.

_________________
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


Top
 Profile  
 
 Post subject: Solved (need better error reporting, though!)
PostPosted: Sun Oct 02, 2005 4:56 pm 
Newbie

Joined: Thu Sep 22, 2005 7:09 pm
Posts: 14
OK, figured out what was causing this. I changed the no-args constructor from private to public and the problem went away. Looks like I can get away with package visibility rather than public, too.

Now I know what was wrong, it makes sense (though I don't yet understand in which circumstances Hiberbate attempts to generate a proxy; private no-arg constructors are working fine in some places).

This is an error that could have been reported a lot more usefully, though!

_________________
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.