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