0

My Spring 3.1.1.RELEASE / Hibernate 3.6.2-Final uses Joda DateTime datatype for some class fields and all was good.

Hibernate 4x and 5x use Jadira as a front-end to Joda for DateTimes.

Hibernate-validator 5x brings in javax.validation 1.1.0.Final, which has a new method I'd like to use.

Jadira doesn't yet work with Hibernate 5x so 4x is as new as I can go.

partial pom:

<!-- adds joda-time , joda-money and JDK types for hibernate4 -->
<dependency>   <!-- jadira is not yet compatible with hibernate 5 -->
  <groupId>org.jadira.usertype</groupId>
  <artifactId>usertype.core</artifactId>
  <version>4.0.0.GA</version>
</dependency>

<!-- JSR 303 validation -->
<dependency>
  <groupId>javax.validation</groupId>
  <artifactId>validation-api</artifactId>
  <!-- <version>1.0.0.GA</version>     brought in by hibernate 4x which I dont want -->
  <version>1.1.0.Final</version>  <!-- brought in by hibernate 5x which I do   want -->
</dependency>

 <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-validator</artifactId>
   <version>4.3.2-Final</version>
   <exclusions>
     <exclusion>
       <groupId>javax.validation</groupId>
       <artifactId>validation-api</artifactId>
     </exclusion>
   </exclusions>
 </dependency>

looking at my dependency tree...

+- javax.validation:validation-api:jar:1.1.0.Final:compile
+- org.jadira.usertype:usertype.core:jar:4.0.0.GA:compile
|  +- (org.hibernate:hibernate-entitymanager:jar:4.3.8.Final:compile - omitted for conflict with 4.3.2.Final)
|  +- org.slf4j:slf4j-api:jar:1.7.12:compile
|  \- org.jadira.usertype:usertype.spi:jar:4.0.0.GA:compile
|     \- (org.slf4j:slf4j-api:jar:1.7.12:compile - omitted for duplicate)
+- org.hibernate:hibernate-validator:jar:4.3.2.Final:compile
+- org.hibernate:hibernate-entitymanager:jar:4.3.2.Final:compile
|  +- (org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile - omitted for conflict with 3.3.0.Final)
|  +- org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile
|  +- org.hibernate:hibernate-core:jar:4.3.2.Final:compile
|  |  +- (org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile - omitted for conflict with 3.3.0.Final)
|  |  +- (org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile - omitted for duplicate)
|  |  +- (org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile - omitted for duplicate)
|  |  +- (dom4j:dom4j:jar:1.6.1:compile - omitted for duplicate)
|  |  +- (org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile - omitted for duplicate)
|  |  +- (org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile - omitted for duplicate)
|  |  +- (org.javassist:javassist:jar:3.18.1-GA:compile - omitted for duplicate)
|  |  +- antlr:antlr:jar:2.7.7:compile
|  |  \- org.jboss:jandex:jar:1.1.0.Final:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
|  +- org.hibernate.common:hibernate-commons-annotations:jar:4.0.4.Final:compile
|  |  +- (org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile - omitted for conflict with 3.3.0.Final)
|  |  \- (org.jboss.logging:jboss-logging-annotations:jar:1.2.0.Beta1:compile - omitted for duplicate)
|  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
|  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.2_spec:jar:1.0.0.Final:compile
|  \- org.javassist:javassist:jar:3.18.1-GA:compile

nowhere else in the tree does javax.validation:validation-api get referenced but on that one line shown. And within the (Eclipse) IDE I do get prompted for the new method, which tells me it's pointing to the correct version (1.1.0.Final)

So I've fought through the upgrade to Spring 4.1.1.RELEASE and Hibernate 4.3.2-Final and got everything working again AFAICT. So I set about doing some bean validation...

Set<ConstraintViolation<Permit>> violations = validator.validate( permit);
if( !violations.isEmpty()) {
    logger.debug( "basic validation FAILED with " + violations.size() + " errors");
    Iterator<ConstraintViolation<Permit>> iter = violations.iterator();
    while( iter.hasNext()) {
        ConstraintViolation<Permit> cv = iter.next();

        logger.debug( "invalidValue:" + cv.getInvalidValue());
        logger.debug( "message:" + cv.getMessage());
        ConstraintDescriptor<?> cd = cv.getConstraintDescriptor();
        Map<String, Object> mapp = cd.getAttributes();
        for( String keey : mapp.keySet()) {
            logger.debug("mapp key:" + keey + ":" + mapp.get(keey));
        }
        Annotation kkk = cd.getAnnotation();
        ConstraintTarget ct = null;
        if( cd.getValidationAppliesTo() == null) {   //  <-- throws AbstractMethodError 

But the new method I'm using throws a runtime AbstractMethod Error...

Exception in thread "main" java.lang.AbstractMethodError: org.hibernate.validator.internal.metadata.descriptor.ConstraintDescriptorImpl.getValidationAppliesTo()Ljavax/validation/ConstraintTarget;

Any ideas on how to track this down?

TIA,

Still-learning Stev

Yosef Weiner
  • 5,432
  • 1
  • 24
  • 37
user1201168
  • 415
  • 6
  • 19

1 Answers1

0

I think the problem is related to hibernate version, Hibernate 4.x is an implementation of javax.validation 1.0 (JSR-303), if you want to use 1.1 (javax.validation), you have to upgrade to hibernate 5.x

UPDATE

See this question: AbstractMethodError on deploying Spring 4.0 in Tomcat 6

Community
  • 1
  • 1
Francisco Hernandez
  • 2,378
  • 14
  • 18
  • Hm. I can't use H5x because of jadira incompatibility. And H4x should be using j.v-api 1.1.0.Final because I explicitly list it in my pom and also exclude j.v-api.1.0.0.GA from h-v.4.3.2.Final , thus forcing it to use 1.1.0.Final. That's mu understanding. – user1201168 Nov 15 '15 at 19:00
  • Yes, I think is going as you say. The point is that hibernate 4x and j.v-api 1.1.0 are not compatibles. Are you using something new from 1.1.0.Final? Can you downgrade to 1.0.0.Final? – Francisco Hernandez Nov 15 '15 at 20:04
  • Huh. I am unaware that H4x and j.v-api 1.1.0.Final are not compatible, only that jadira and H5x are incompatible. H4 and j.v-api 1.1.0.Final seem to be cooperating ok except for this one rotten method - the method I need from 1.1.0.Final that is not in 1.0.0.GA . How can one programmatically prove during execution which version of a package a given object or method comes from? – user1201168 Nov 16 '15 at 06:02
  • You cannot just mix and match dependency versions. As suggested here, Hibernate Validator 4.x aligns with Bean Validation 1.0 and Hibernate Validator 5.x with Bean Validation 1.1. If you can use HV 4.x with the BV 1.1 jar is ok as long as it works, but it is not recommended nor supported. Also, you need to realize that Bean Validation is just a specification. The implementation is in Hibernate Validator. You are expecting that an earlier version of Validator (4.x) implements functionality which was added for later versions of the spec (1.1). Ain't going to work. – Hardy Nov 24 '15 at 11:48