7 Replies Latest reply on Feb 17, 2008 6:13 PM by pmuir

    JBoss 4.2.1GA and Hibernate validator - broken

    wschwendt

      The following is not a Seam issue, even though it may be important to Seam users.

      Bug description:
      ==========

      JBoss AS 4.2.1GA is shipped with
      Hibernate Core 3.2.4.sp1
      Hibernate Annotations 3.2.1.GA
      Hibernate EntityManager 3.2.1.GA

      The problem is that instantiation of a Hibernate Validator specified with the org.hibernate.validator.Min annotation fails with an exception (see below).

      How to reproduce the bug:
      ===================
      Use JBossAS4.2.1GA and the Seam hotel booking example and annotate method getPrice() of org.jboss.seam.example.booking.Hotel with @Min(0). Then deployment of the hotel booking application fails.

      2007-08-06 06:13:45,540 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting failed persistence.units:ear=jboss-seam-booking.ear,jar=jboss-seam-booking.jar,unitName=bookingDatabase
      java.lang.IllegalArgumentException: could not instantiate ClassValidator
       at org.hibernate.validator.ClassValidator.createValidator(ClassValidator.java:294)
       at org.hibernate.validator.ClassValidator.createMemberValidator(ClassValidator.java:262)
       at org.hibernate.validator.ClassValidator.initValidator(ClassValidator.java:215)
       at org.hibernate.validator.ClassValidator.<init>(ClassValidator.java:134)
       at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:318)
       at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
       at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
      
      ...
      



      Question:
      =======

      What needs to be done in order to successfully use the org.hibernate.validator.Min validator? Could a solution be the replacement of the Hibernate packages shipped with JBoss AS 4.2.1GA with more recent versions? I tried to replace those Hibernate jars with Hibernate core 3.3.0GA, Hibernate EntityManager 3.3.1.GA, Hibernate Annotations 3.3.0GA and Hibernate Validator 3.0.0GA, but this produces a a classloading error when Hibernate is started up.

      Are there any instructions out there how JBossAS needs to be configured when using the latest Hibernate versions?


        • 1. Re: JBoss 4.2.1GA and Hibernate validator - broken
          pmuir

          The hibernate-all.jar that we provide containing hibernate is actually quite old. The api for validator has changed between it and the version in JBossAS 4.2.1. So, replace hibernate-all.jar with the jars from hibernate/lib (in the seam distro).

          • 2. Re: JBoss 4.2.1GA and Hibernate validator - broken
            wschwendt

            Thanks for your reply, Pete. I forgot to mention that I'm using the CVS based Seam 2. When building the Seam example such as the hotel booking example, by default no Hibernate jars are packaged. Rather, the Hibernate jars shipped with JBoss AS are used (I'm using JBoss 4.2.1GA).

            I looked at the hibernate/lib directory of the CVS based Seam:

            It includes Hibernate 3.2.1.ga, Hibernate Annotations 3.2.1.GA and Hibernate EntityManager Version: 3.2.1.GA.

            Thus, only the Hibernate version is more recent than the one shipped with JBoss 4.2.1GA, but the Hibernate Annotations and Hibernate EntityManager are the same as shipped with JBoss 4.2.1GA. While there are more recent versions available (Hibernate EntityManager 3.3.1GA and Hibernate Annotations 3.3.0GA, with Hibernate validator now separate in Hibernate validador 3.3.0GA.jar), these are not included in the Seam based CVS.

            I also forgot to mention that only the @Min Hibernate validator failed. The @NotNull validator and other validators such as @Length are working fine.

            • 3. Re: JBoss 4.2.1GA and Hibernate validator - broken
              pmuir

              Sure, no hibernate stuff from Seam is packaged in as runtime dependencies, but, for the examples at least, the hibernate-all.jar *is* used to compile the example (and hence the @Min annotation). The api for @Min has changed between the version of hibernate-all (not sure what this is btw) we have and the hibernate in the AS. I was able to fix it by removing hibernate-all.jar and adding the hibernate/lib to the compile classpath.

              • 4. Re: JBoss 4.2.1GA and Hibernate validator - broken
                tynor

                What he said. Our project just hit a different bug with the validators in JBoss 4.2.1 that has been fixed in validators-3.3.0 (@Email does not tolerate null values as happens with empty JSF text fields -- http://opensource.atlassian.com/projects/hibernate/browse/HV-3).

                Clear instructions for how to update to a fixed version would be very helpful!

                "wschwendt" wrote:
                The following is not a Seam issue, even though it may be important to Seam users.
                ...
                Question:
                =======

                What needs to be done in order to successfully use the org.hibernate.validator.Min validator? Could a solution be the replacement of the Hibernate packages shipped with JBoss AS 4.2.1GA with more recent versions? I tried to replace those Hibernate jars with Hibernate core 3.3.0GA, Hibernate EntityManager 3.3.1.GA, Hibernate Annotations 3.3.0GA and Hibernate Validator 3.0.0GA, but this produces a a classloading error when Hibernate is started up.

                Are there any instructions out there how JBossAS needs to be configured when using the latest Hibernate versions?


                • 5. Re: JBoss 4.2.1GA and Hibernate validator - broken
                  tynor

                  FWIW,

                  I've managed to get a working @Email validator by replacing all the hiberate*.jar files in my JBOSS/server/default/lib directory with the following:

                  hibernate-annotations.jar (from hibernate-annoations-3.3.0.GA)
                  hibernate-commons-annotations.jar (ditto)
                  hibernate-entitymanager.jar (from hibernate-entitymanager-3.3.1.GA)
                  ejb3-persistance.jar (from hibernate-entitymanager-3.3.1.GA)
                  hibernate-validator.jar (from hibernate-validator-3.0.0.GA)
                  hibernate3.jar (from hibernate-3.2.5.ga)


                  I've replaced the lib/hibernate-all.jar bundled with Seam with the above for compile-time and all seems to work OK so far.

                  I've not tested the @Min validator that originally started this thread.

                  Seam 1.2.1-GA
                  JBoss 4.2.1


                  • 6. Re: JBoss 4.2.1GA and Hibernate validator - broken

                    Does anyone know if this problem still exists in Seam 2.0?

                    • 7. Re: JBoss 4.2.1GA and Hibernate validator - broken
                      pmuir

                      We now have a current version of Hibernate in 2.0.1