Domain Driven Design

What I can say, still a new new thing to do if you are working with a serious project, think it twice. It had given me some interesting challenge. Spring, aspectj, and Hibernate, the domain object are injected with the repository. Some how, domain driven design made me think that Eric Even's "Entity" are similar to EJB's "Entity" bean. They are all heavy objects. They all hide the details about the database operations. They all need this factory and service to complete the life cycle. Let me know if I am wrong about this.

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>

Comments

Popular posts from this blog

Spring framework, Hibernate and MySQL Replication

the Art of Kindling a Light in the darkness of mere being

Exposed Domain Object implemented with Spring Aspect Transaction Control + AspectJ