0

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:

Error 500 shown

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:

enter image description here

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
Joseph
  • 149
  • 1
  • 2
  • 9
  • What version of hibernate you are using? This method is in the 4.x.x . Below link has more information https://stackoverflow.com/questions/23903425/java-lang-noclassdeffounderror-org-hibernate-internal-coremessagelogger – user8271644 Jul 25 '17 at 17:09
  • org.hibernate hibernate-core 5.2.10.Final So, I use 5.2.10 Thank you for your fast reply. – Joseph Jul 25 '17 at 17:11
  • 1
    can you try using a 4.x.x version and see if the error goes away – user8271644 Jul 25 '17 at 17:18
  • Thank you for your reply. I have edit the post with new information about your solution. Maybe its a good approach. Maybe can you suggest me another way to force static code invokation to avoid Classforname? – Joseph Jul 26 '17 at 10:30

0 Answers0