I'm deploying my REST project on a Glassfish 4.1.1 bundle Netbeans server. As a maven dependency, I have included an external netbeans project already done and tested, that uses Hibernate to provide functionallity. So I should use this Java library project in my REST web services project.
When I debug my REST project, once deployed and started Glassfish in debug mode, REST services are well called and everything is going nice until a call to any method that uses Hibernate (from the external lib project) is needed. Then crashes as shown below in the attached image.
At the starting of Glassfish sever, I noticed these two warnigs:
Warning: The web application [unknown] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Warning: The web application [unknown] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Information: HV000001: Hibernate Validator 5.1.2.Final
And finally, error shown by browser when any Hibernate involucred sentence is invoked is:
exception
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
root cause
org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
root cause
java.lang.NoSuchMethodError: org.hibernate.internal.CoreMessageLogger.debugf(Ljava/lang/String;I)V
I add screenshot:
Thank you, J.
----------- EDIT WITH SPECIFIC LINE WHERE CRASHES ------------
public static void openSession(){
try{
if (!init){
//First inicialization. Force execute static block.
Class.forName(SessionFactory.class.getCanonicalName());
init = true;
}
currentSession = SessionFactory.sessionFactory.getCurrentSession();
currentSession.beginTransaction();
It crashses at Class.forName(SessionFactory.class.getCanonicalName()). I invoke this method in order to force the class SessionFactory to execute its static block method that configures Hibernate only once. With suggested solution to downgrade hibernate librery to 4.x.x, it seems to work, but I'm forced to change some newer methods to adapt my code to this version (native querys are different, class Metadata in configuration is not present...). Further, I have new problems when I need to create new basical Hibernate objets for a consult, as Query:
public static User getUserById(Long id) {
try {
String query = "SELECT u FROM User u WHERE u.id = " + id;
Query sentence;
Crashes as:
Further, I have the same warning at the start:
Warning: The web application [unknown] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Warning: The web application [unknown] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Information: HV000001: Hibernate Validator 5.1.2.Final