14 Replies Latest reply on Oct 23, 2013 8:32 AM by Fabio Schmitz Tani

    Jboss 5.1 and hibernate jars

    Syed Mahdi Apprentice

      I was following this blog post online, It was quite helpful. But I have the same issue that the last commentor had. I tried to find his post but I couldnt really find it.

       

      my issue is pretty similar to his :

       

      I ahve jboss 5.1 which has some hibernate jars in it common/lib folder. I dont want to use those jars and what to use the ones I have packaged in my war.

       

      the libs are in the WEB-INF/lib folder there is one particular jar : hibernate-validator.jar. this is very different from the one jboss has its own lib folder. the structure is very different.

       

      I made a jboss-web.xml file and placed it in the WEB-INF folder.

       

      /********************************************/

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-web>
          <context-root>my-app</context-root>
      <class-loading java2ClassLoadingCompliance="false">
      <loader-repository>
      com.example:loader=my-app.war
      <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
      </loader-repository>
      </class-loading>
      <resource-ref>
               <res-ref-name>jdbc/myappDS</res-ref-name>
               <res-type>javax.sql.DataSource</res-type>
               <jndi-name>java:/jdbc/myappDS</jndi-name>
          </resource-ref>
      </jboss-web>

      /********************************************/

       

       

      It still is picking up the older hibernate-validator.jar in the commons/lib folder. how can I make corrections to this so that my classloading works.

       

      I also tried the exact listing from the link for the xml file and it still didnt work. i also created jboss-app.xmla nd placed it in the WEB-INF/ folder and it didnt work either.

       

      the exception coming is :

      Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hib ernate.annotations.common.reflection.ReflectionManager)         at java.lang.Class.getConstructor0(Class.java:2706)         at java.lang.Class.getDeclaredConstructor(Class.java:1985)         at org.hibernate.cfg.AnnotationConfiguration.applyHibernateValidatorLegacyConstraintsOnDDL(AnnotationConfiguration.java:443)         ... 134 more

       

      I have checked that classValidator is in the jboss/common/lib/hibernate-validator.jar

      The one that I have does not have this class.

        • 1. Re: Jboss 5.1 and hibernate jars
          Syed Mahdi Apprentice

          I did a verbose output on my jboss

           

          here is the output:

           

          http://codepad.org/HOIk13Im

           

          It seems that its loading both the jars. But looking into the one in jboss for this...

           

           

          i searched on this issue it seems there have been some jira tickets already present..

           

          http://jira.codehaus.org/browse/GRAILS-5606

           

          http://jira.springframework.org/browse/SPR-6783

           

          http://markmail.org/message/7byy6kx5ljx5kwve

           

          the solution is NOT recommened i think. we should not delete and replace the jars already in jboss cos jboss might be configured with them.

          i have tried classloading. and i already have the hibernate-validator-4.0.2 jar which they say they is needed to actually resolve this issue.

           

           

          verbose is the output as an attached file.

           

          I dont know what to make out of this. Is this an issue in JBOSS, that the jboss-web.xml doesnt work.

           

          i will appreciate any help on this.

           

          Thanks

           

          Syed

          • 2. Re: Jboss 5.1 and hibernate jars
            Syed Mahdi Apprentice

            I would like to bump this up as as serious issue: I think this is happening in jboss 5.x and above versions, havnet tested it on 6.0

             

            Am I right here, Has anyone tested this out in the jboss team. This is an issue if you are trying to run your app on the same jboss as another app that uses a different jar. Even if it is the only app on jboss, customizing jboss and esp validator jar can give issues to jboss itself, wont it not!!?

             

            Thanks for any feedback.

            • 3. Re: Jboss 5.1 and hibernate jars
              Syed Mahdi Apprentice

              JaiKiran helped me out on this one (Thanks) If you need to resolve this without touching the Jboss/commmon/lib folder you have the option to set "hibernate.validator.apply_to_ddl" to false   false

               

              <property name="hibernate.validator.apply_to_ddl">false</property>

               

              But the story for me didnt end there:  I got another error related in the same class but in some other method:

               

               

              there was a classcastexception at org.hibernate.cfg.AnnotationConfiguration : org.hibernate.validator.event.ValidateEventListener cannot be cast as PreInsertEventListener (org.hibernate.cfg.AnnotationConfiguration 996)  well something like that: in order to by pass that i did the same as JaiKiran told me and went into the AnnotationConfiguration code and found out that this property comes into play and you have to set it false :

               

              <property name="hibernate.validator.autoregister_listeners">false</property>

               

              hope this helps someone. It did help me. I am able to deploy new hibernate 3.5.3 with hibernatevalidator.4.0.2-GA.jar and not remove anything from jboss/libs.

              Thanks

              Syed.

              • 4. Re: Jboss 5.1 and hibernate jars
                jaikiran pai Master

                Good to know, you got it working And thank you for posting the details here.

                1 of 1 people found this helpful
                • 5. Re: Jboss 5.1 and hibernate jars
                  Syed Mahdi Apprentice

                  Well in the bit torrent world we have leeches and seeds, leeches only download and never upload,

                  seeds do both.

                   

                  I want to be a seed and actually post the solutions and NOT be a leech and just ask the question and never come back if i found a solution myself.

                  • 6. Re: Jboss 5.1 and hibernate jars
                    Fabio Schmitz Tani Newbie

                    Syed Mahdi,

                     

                    I know it has been some time since you've posted, but I was wondering if you could shine some more light into your solution.

                     

                    I Basically have a similar setup, I have classloading configured to use the application libraries first, and I've bundled hibernate with my app (greatly because of possible conflicts with the bundled hibernate jars), unfortunately, I was unable to apply your solution so far.

                     

                    What has worked for me is to substitute the validator in the common/lib, but a side-effect is that admin-console won't work anymore due to compatibility issues with the new hibernate-validator.

                     

                    So that's why I searched and found your thread.

                     

                    So if you have the time, I've added to my persistence.xml the properties:

                    <property name="hibernate.validator.apply_to_ddl">false</property>

                    <property name="hibernate.validator.autoregister_listeners">false</property>

                     

                    And I've bundled the hibernate jars and hibernate-validator in the WEB-INF/lib of my application.

                     

                    My server still seems to be picking up Jboss hibernate-validator.jar instead of the one deployed with the web application.

                    • 7. Re: Jboss 5.1 and hibernate jars
                      jaikiran pai Master

                      Which exact version of JBoss AS is this? And which versions of (various) Hibernate jars are you packaging in your application? Is it a .war file? What does the jboss-web.xml look like and which exact jar files are present in WEB-INF/lib?

                       

                      Finally, do you get any exceptions? If yes, please post that stacktrace. You also mention that the server is picking up the hibernate-validator from the common/lib instead of from your packaged application. Did you see any logs or some other thing, that made you suspicious about that?

                      • 8. Re: Jboss 5.1 and hibernate jars
                        Fabio Schmitz Tani Newbie

                        Jakiran Pai,

                         

                        My environment is JBoss AS 5.1.0, JBoss EAP.

                         

                        My apps are using ClassLoader isolation, so I've bundled the compatible hibernate jars with the applications, the problem is that the bundled hibernate-validator that comes with JBoss AS 5, is incompatible with the hibernate in the applications, and bundling the validator with the application does not seem to work.

                         

                        Fortunately I was able to add the upgraded validator in the common/lib, and for the applications which depend on older validation I was able to bundle the older validator with the application and it worked.

                         

                        What is odd is that having the old hibernate-validator in common/lib and bundling the new validators doesn't work, but doing it the other way around seems to work just fine.

                        • 9. Re: Jboss 5.1 and hibernate jars
                          rfmj2ee Newbie

                          Hello everyone,

                           

                           

                          I've been working on an WAR application (migration from other AS to JBoss 5.1) with a similar setup, but the WEB-INF/lib doesn't contains the hibernate-validator lib, when I deploy it, it crashes and shows "Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java..."  error.

                           

                           

                          Seems that the server loads its common/legacy hibernate jars, and, when I deploy the app(mine) the deployer(s) doesn't find the validator one(because it isn't on WAR). It loads fine app's hibernate core annotations and entity manager inside app lib... and... the server legacy validator,  maybe this is the cause... is this approach rigth anyway?

                           

                           

                          I follow the steps that you said (jboss-web with custom loader) and still crashes, the solution that I find for my setup was copy the compatible version of validator to the WEB-INF/lib folder + follow the steps to force deployer use it instead of server's common.  

                           

                           

                          I am worry about side effects on my app including this library that wasn't needed before...

                           

                           

                          What do you think about???

                           

                           

                          Thank you all

                          • 10. Re: Jboss 5.1 and hibernate jars
                            Fabio Schmitz Tani Newbie

                            Hi rfmj2ee,

                             

                            Unfortunately the hibernate-validator jars won't work just moving them inside the WEB-INF/lib folders, you will actually need to replace your Jboss/lib legacy hibernate-validator with a new version compatible with your hibernate version.

                             

                            The side effect is that applications that depend on the legacy hibernate-validator will need to be deployed with the legacy validator in the WEB-INF/lib of the application. With the jboss-web.xml inversing the Classloader order to get the libs from the WEB-INF first.

                             

                            Some Seam 2 applications and the sample applications from JBoss are an example of applications that depend on the legacy validator, so you will need to add the legacy jar inside the WEB-INF/lib of these applications if you plan to use them.

                             

                            Hope this helps you out.

                            • 11. Re: Jboss 5.1 and hibernate jars
                              rfmj2ee Newbie

                              Hi fstani thank you for your quick aswer,

                               

                              It works for me, is the current solution that I found keepin' the jboss/lib legacy jars and copy the compatible version on validator on my WEB-INF /lib.

                               

                              My problem is that the app is currently running on Tomcat and others AS without hibernate-validator jar on WEB-INF/lib, and I don't understand why in JBoss I got this issue (this is my first migration to JBoss Server). Maybe I forgot something on the config, or maybe there is a configuration to tell my aplication to ignore some jars on the classpath instead of load WEB-INF stuff first and then the legacy ones.

                               

                              I want to tell deployers to don't load hibernate-validator because app don't need it and could be the cause of side effects on it. Or maybe this is the solution and I don't have to be afraid.

                               

                              Thank you again.

                              • 12. Jboss 5.1 and hibernate jars
                                Ronni Lin Newbie

                                Hi,

                                 

                                I have spend the whole afternone strugling with this classloading issue.

                                 

                                At the end i was so frustrated and had to look at the code in git of hibernate.

                                 

                                https://github.com/hibernate/hibernate-core/blob/3.5/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java

                                 

                                The method that is causing all these problems is:

                                ..

                                private void applyHibernateValidatorLegacyConstraintsOnDDL()

                                ...

                                 

                                A Class.forName() called for the org.hibernate.validator.ClassValidator this results in loading the class from the JBoss hibernate-validator jar because this class doesn't exist in the later versions of hibernate.

                                 

                                So, the only way to work arround this is change the code,  remove the jars from jboss or set the 'hibernate.validator.apply_to_ddl' to false als mentioned before.

                                 

                                Or upgrade hibernate to version 3.6+. Maybe this issues goes away, because the code has changed. But other issues will arrise

                                • 13. Re: Jboss 5.1 and hibernate jars
                                  AZ AZ_ Newbie

                                  I have solved this issue and other. All the complete detail is provided on StackOverFlow so please follow the link below and don't mess with Jboss config xml as they will become a debug hell for you later. It's simple and pretty straight forward and most amazingly you just have to add certain context-params to you OWN PROJECT

                                  http://stackoverflow.com/questions/19534610/jboss-4-2-3-add-jsf-2-x-support-classcastexception-validateeventlistener-sol…

                                  • 14. Re: Jboss 5.1 and hibernate jars
                                    Fabio Schmitz Tani Newbie

                                    AZ AZ_,

                                     

                                    Unfortunately your solution is targeting JBoss 4.2.3, this thread is regarding JBoss 5.1 which has changed significantly how class-loading works. You should test your solution with the correct version of JBoss,

                                     

                                    As you can see by Ronni Lin's post, there is a faulty code that causes the class to load, and the whole jar hell happens due to that.

                                     

                                    Thanks for the contribution to this thread.