Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:25:10+00:00 2026-05-22T12:25:10+00:00

Error: Type mismatch: cannot convert from Set<ConstraintViolation<capture#1-of ?>> to Set<ConstraintViolation<Class<?>>> My code: public class

  • 0

Error:

Type mismatch: cannot convert from Set<ConstraintViolation<capture#1-of ?>> to Set<ConstraintViolation<Class<?>>>

My code:

public class validateValue(Class<?> beanType, String propertyName, Object value, Class<?>... groups){
    TraversableResolver tr = new MyTraversableResolver(); 
    Validator validator = Validation.buildDefaultValidatorFactory().usingContext().traversableResolver(tr).getValidator();
    final Set<ConstraintViolation<Class<?>>> constraintViolations = validator.validateValue(beanType, propertyName, value, groups);
}

private class MyTraversableResolver  implements TraversableResolver {

    public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
      return traversableObject == null || Hibernate.isInitialized(traversableObject);
      }
      public boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
          return true;
      }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:25:10+00:00Added an answer on May 22, 2026 at 12:25 pm

    @JustinKSU is correct about changing the wildcard (?) to a type arg (T). The other issue is that validator.validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) doesn’t return a set of constraint violations on the type’s class, which would be:

    Set<ConstraintViolation<Class<T>>>
    

    …but rather it returns a set of constraint violations on the type:

    Set<ConstraintViolation<T>>
    

    It’s a subtle difference to see, but it’s noticeable if you check the error message closely and count the angle brackets.

    So, your code should be as below. I simplified the validator creation for purposes of the example. I also added a return value since I assume you want to do something with the results.

    public <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) {
        Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
        final Set<ConstraintViolation<T>> constraintViolations = validator.validateValue(beanType, propertyName, value, groups);
        return constraintViolations;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Map testMap = new HashMap(); for(Map.Entry<String, Object> entry:testMap.entrySet()){ } it has error tip:Type mismatch:
What could be the reason, that I get the the Run-Time Error '13' Type
In order to avoid Java exceptions I'm using Scala's exception handling class. However, when
Here is my code: open System let rec gcd a b = match b
#include <map> #include <list> template < typename K, typename V> class LruCache { private:
I need to remove the Component in the Center of the JPanel , but
This compiles (1.6) List<? extends Object> l = new ArrayList<Date>(); But this does not
I'm sure this is a very simple question but please take a look at
Ok, so i have a custom object that is a myUser. myUser looks like
I'm trying to take an ADO Recordset and then loop through it to parse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.