History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: HHH-361
Type: Bug Bug
Status: Closed Closed
Resolution: Rejected
Priority: Minor Minor
Assignee: Unassigned
Reporter: Robert Watkins
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hibernate3

Classes now longer seem to work with private zero-arg constructors

Created: 18/Apr/05 02:11 AM   Updated: 19/Apr/05 12:38 AM
Component/s: core
Affects Version/s: 3.0 final
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown
Environment: Hibernate 3.0, Oracle


 Description  « Hide
Classes that previously worked fine with Hibernate 2.1.6 are having problems with Hibernate 3.0 because they have private zero-arg constructors.

If the constructors are made package-private or higher, it works fine.

This may be a bug in the version of cglib distributed with Hibernate 3.0 (cglib-2.1)

Example class (based on real scenario):
package foo.bar;

public class Foo {

private Bar bar;

/** for hibernate */
  private Foo() { }

public Foo(Bar aBar) { setBar(aBar); }

public Bar getBar() { return bar; }

private void setBar(Bar aBar) { bar = aBar; }
}

Stack trace:
18/04/2005 17:05:24 org.hibernate.proxy.CGLIBLazyInitializer getProxyFactory SEVERE: CGLIB Enhancement failed: foo.bar.Foo
java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at net.sf.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:682)
at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:494)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:215)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:373)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:281)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:640)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:94)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:42)
at org.hibernate.tuple.PojoTuplizer.buildProxyFactory(PojoTuplizer.java:139)
at org.hibernate.tuple.AbstractTuplizer.<init>(AbstractTuplizer.java:83)
at org.hibernate.tuple.PojoTuplizer.<init>(PojoTuplizer.java:54)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:47)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:212)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:400)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1054)
at foo.bar.HibernateConfigTest.testCreateSessionFactory(HibernateConfigTest.java:152)
...


 All   Comments   Work Log   Change History   FishEye      Sort Order:

Gavin King - [18/Apr/05 10:27 AM ]
As always, private constructors cannot be used with <class lazy="true"/>. that is now the default.

Robert Watkins - [18/Apr/05 06:54 PM ]
Yes, that was the cause, Gavin. Thanks for the diagnosis.

Perhaps this side effect of using lazy classes (and the fact that is the default in Hibernate 3) could be better documented, however?

Christian Bauer - [19/Apr/05 12:24 AM ]
It has been documented for some years now.

Robert Watkins - [19/Apr/05 12:38 AM ]
I don't mean to sound snippy, Christian, but where? I wasn't aware of the restriction, and it really bit me. And yes, I've read the doco - but I've never used lazy classes before (lazy collections, yes, lazy classes, no)

All it needs is a sentence or two in the migration guidelines in the metadata section.