Wednesday, August 25, 2010

Exception in thread "main" java.lang.NoClassDefFoundError: javax.persistence.Cacheable

When you are working with Hibernate using the Annotations, you will get the following exceptions
Exception in thread "main" java.lang.NoClassDefFoundError:javax.persistence.Cacheable 
even though you have added the required libraries that comes with the Hibernate distribution final 3.5 as well as ejb3-persistence.jar.
The reason for this javax.persistence.Cacheable is part of JPA 2.0 specification. To overcome this issue, you need to add the following JAR file hibernate-jpa-2.0-api-1.0.0.Final.jar, which will be available under /lib/jpa directory in Hibernate distribution.

Happy programming

Initial SessionFactory creation failed.org.hibernate.AnnotationException: java.lang.NoSuchMethodException

When you have the default libraries provided by the Hibernate 3.5 (hibernate-annotations.jar)and also have the ebj3-persistence.jar to support the annotation feature, you will be end up with the following exception on runtime
Initial SessionFactory creation failed.org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
This is because of the incompatible types, if you are using the EJB based Annotations feature just, remove the hibernate-annotations.jar from your library. This will resolve the above runtime exceptions.

Saturday, August 14, 2010

java.net.BindException: Address already in use: JVM_Bind 8009

In most of our development machines, we would have installed so many things for our practice purpose, which will create hell of issues, on the port number. So many of you, have encountered the following exceptions, when starting our server
java.net.BindException: Address already in use: JVM_Bind 8009.
How to figure out which application is occupying my port
In Windows
1. In MS-DOS, send command "netstat -ao". You can get network information for all processes.

2. Find out the one using port 8009, get the PID.
3. Find out the process with the PID you just got from windows task manager and shut it down. (By default the Task Manager doesn't show the PID. You have to add it from the menu View Select columns)
4. That's it, restart your server