Skip to main content
deleted 2 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58

The error reported indicates that you are trying converting the String OnboardingTaskStatus.2769df0841 to a OnboardingTaskStatus enumeration value which is not undefineddefined.

The error reported indicates that you are trying converting the String OnboardingTaskStatus.2769df0841 to a OnboardingTaskStatus enumeration value which is not undefined.

The error reported indicates that you are trying converting the String OnboardingTaskStatus.2769df0841 to a OnboardingTaskStatus enumeration value which is not defined.

added 724 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58

Finally, it seems that you are using some kind of conversion mechanism under the hood for converting the status String to the corresponding enum value in your Specification; on the contrary, as you can check in the Hibernate source code, this line will raise a different error:

predicates.add(cb.equal(root.get("status"), params.getStatus())); 

Something like:

Parameter value ... did not match expected type ... 

If that is the case, please, review that logic as well, perhaps the problem is there.

Finally, it seems that you are using some kind of conversion mechanism under the hood for converting the status String to the corresponding enum value in your Specification; on the contrary, as you can check in the Hibernate source code, this line will raise a different error:

predicates.add(cb.equal(root.get("status"), params.getStatus())); 

Something like:

Parameter value ... did not match expected type ... 

If that is the case, please, review that logic as well, perhaps the problem is there.

added 1754 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58

If you actually need to check if the enumeration value exists and still use String for representing status in your search criteria, you have multiple options.

You can for example use the method isValidEnum in the EnumUtils class from the commons-lang library:

if(EnumUtils.isValidEnum(OnboardingTaskStatus.class, params.getStatus())){ predicates.add( cb.equal( root.get("status"), OnboardingTaskStatus.valueOf(params.getStatus()) ) ); } 

You can use the getIfPresent method from Guava's Enums class:

Optional<OnboardingTaskStatus> optStatus = Enums.getIfPresent(OnboardingTaskStatus.class, params.getStatus()); if(optStatus.isPresent()){ predicates.add( cb.equal( root.get("status"), OnboardingTaskStatus.valueOf(optStatus.get()) ) ); } 

This other SO question provides several alternatives from Jon Skeet and others.

With Java 8, you have several options as well. In addition to the ones provided in other answers, you can try for example:

Optional<OnboardingTaskStatus> optStatus = EnumSet.allOf(OnboardingTaskStatus.class) .stream() .filter(e -> e.name().equals(params.getStatus())) .findAny(); if(optStatus.isPresent()){ predicates.add( cb.equal( root.get("status"), OnboardingTaskStatus.valueOf(optStatus.get()) ) ); } 

If you actually need to check if the enumeration value exists and still use String for representing status in your search criteria, you have multiple options.

You can for example use the method isValidEnum in the EnumUtils class from the commons-lang library:

if(EnumUtils.isValidEnum(OnboardingTaskStatus.class, params.getStatus())){ predicates.add( cb.equal( root.get("status"), OnboardingTaskStatus.valueOf(params.getStatus()) ) ); } 

You can use the getIfPresent method from Guava's Enums class:

Optional<OnboardingTaskStatus> optStatus = Enums.getIfPresent(OnboardingTaskStatus.class, params.getStatus()); if(optStatus.isPresent()){ predicates.add( cb.equal( root.get("status"), OnboardingTaskStatus.valueOf(optStatus.get()) ) ); } 

This other SO question provides several alternatives from Jon Skeet and others.

With Java 8, you have several options as well. In addition to the ones provided in other answers, you can try for example:

Optional<OnboardingTaskStatus> optStatus = EnumSet.allOf(OnboardingTaskStatus.class) .stream() .filter(e -> e.name().equals(params.getStatus())) .findAny(); if(optStatus.isPresent()){ predicates.add( cb.equal( root.get("status"), OnboardingTaskStatus.valueOf(optStatus.get()) ) ); } 
added 447 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58
Loading
added 447 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58
Loading
added 139 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58
Loading
added 33 characters in body
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58
Loading
Source Link
jccampanero
  • 53.6k
  • 3
  • 26
  • 58
Loading