Thursday, October 8, 2015

Solving the issue of not loading OneToMany eager fetch entities

When you have Hibernate as the JPA provider,sometimes when your JPA entity classes have multiple OneToMany eager fetches, it doesn't load all the entities it has related to in some entity relations. Instead it only loads one entity on some of the relations. I had this problem multiple times during the development of the JPA entity classes.

Even though my preference is to continue according to the pure JPA specification, I couldn't find a fix for the issue using JPA. Finally found a fix by using a Hibernate specific annotation and it didn't arise anymore after putting it along with the JPA annotations. The Hibernate annotation is @Fetch(FetchMode.SELECT) annotation along with JPA @OneToMany annotation.

I found the solution in below link and it has the relevant explanation how it is working.

http://stackoverflow.com/questions/17566304/multiple-fetches-with-eager-type-in-hibernate-with-jpa

Sometimes, you need to bare with these fixes even though you don't like to mix up Hibernate and JPA annotations together.

Fixing Maven Out of Memory issue

When your are issuing maven builds for your projects, it might gives you out of memory issues. Then putting below command on your terminal will keep the headache away from you.
 export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"  


If this is frequently happening, add this setting to your environment variables.