-->
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.  [ 2 posts ] 
Author Message
 Post subject: exception "CGLIB Enhancement failed" after session
PostPosted: Wed Nov 09, 2005 6:00 am 
Newbie

Joined: Wed Nov 09, 2005 5:28 am
Posts: 3
i have the following simple entity
Code:
@Entity(access = AccessType.FIELD, name = "CGLibEntity")
public class CGLibEntity {
    @Id(generate = GeneratorType.AUTO)
    private Long _id;

    @Version
    private int _version = 0;

    @Column(name = "name")
    private String _name;

    private CGLibEntity() {
    }

    public CGLibEntity(String name) {
        _name = name;
    }
}


and a simple JUnit test like
Code:
   
public void testConstructorNotFound(){
        CGLibEntity entity1 = new CGLibEntity("1");
        _session.save(entity1);
        _session.flush();
        _session.clear();

        Query query = _session.createQuery("From CGLibEntity");
        for(Iterator it = query.iterate(); it.hasNext();) {
            System.out.println( (CGLibEntity) it.next() );
        }
    }


without the _session.clear() line, everything works ok .. otherwise, query.iterate() generates the below CGLib exception :
Code:
org.hibernate.event.def.DefaultLoadEventListener onLoad
INFO: Error performing load command
org.hibernate.HibernateException: CGLIB Enhancement failed: com.GenericTests.CGLibInitializeErrors.CGLibEntity
   at org.hibernate.proxy.CGLIBLazyInitializer.getProxy(CGLIBLazyInitializer.java:80)
   at org.hibernate.proxy.CGLIBProxyFactory.getProxy(CGLIBProxyFactory.java:47)
.....


i followed the error deep in the code and it's because a constructor for the CGLibEntity is not found.

i tried to change the visibility of my constructor and see how that works with session.clear() .. the results are below:
- session.clear() + private contructor -> CGLib exception
- session.clear() + public or protected contructor -> fine
- no session.clear + any constructor visibility -> fine

is this a limitation/issue of CGLib or Hibernate , or i'm doing something wrong?

i am using: Hibernate Core 3.1 rc2, Hibernate Annotations 3.1 beta 5, JDK 1.5.0_04, cglib 2.1.2


many thx in advance,
paul


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 6:50 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the documentation. Constructors have to be at least package-visible to be used with proxies.


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