This is about a subtle problem during my development of a project. It related to hibernate lazy initialization. When the domain object loaded with hibernate configured lazy="true", and spring + run time aspectjweaver was trying to inject in the data store, I had this "CGLIB Enhancement failed [classname]" failure from hibernate. . Took me an hour to find out what really happened. Had no clue at first. Then there is no other choice other than hopping into the source code. What I found is that the hibernate is returning a cglib class instead of a real domain object, so when spring is doing the setDataStore as the aspectj aop.xml file instructed to, it fail:
.. nested exception is org.springframework.beans.PropertyBatchUpdateException;
To get arround of this, exclude the CGLIB classes.
<aspectj>
<weaver options="-showWeaveInfo
-XmessageHandlerClass:org.springframework.aop.aspectj.AspectJWeaverMessageHandler">
<include
within="com.my.model..*">
<exclude
within="com.my.model..*CGLIB*">
</exclude>
<aspects>
<include
within="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
</include>
</aspects>
</include>
</weaver>
</aspectj>
0 comments:
Post a Comment