• spring-boot-starter-parent: 2.3.4.RELEASE
  • using spring-boot-starter-data-jpa
  • spring.jpa.hibernate.ddl-auto = create-drop -> it create DB table Subscriber as accpected
  • Enum:
public enum Application {
    ALL("ALL"),
    PORTAL_CLANIC("PORTAL_CLANIC"),
    DNS("DNS"),
    DOMAIN_REG("DOMAIN_REG"),
    UPIS("UPIS"),
    IP_REG("IP_REG"),
    PREDAL("PREDAL"),
    VID_RESERVATION("VID_RESERVATION"),
    WAREHOUSE("WAREHOUSE");
}
  • Entity:
@Entity
@Audited
@Data
@NoArgsConstructor
public class Subscriber implements Serializable{
 private EnumSet<Application> apps;
}
  • JpaRepository:
public interface SubscriberRepository extends JpaRepository<Subscriber, Long> {
    Subscriber findByEmail(String email);
    List<Subscriber> findByAppsIn(EnumSet<Application> apps);
}
  • Service:
@Service
@Slf4j
public class SubscriberService {
    @Autowired
    SubscriberRepository subscriberRepo;

    public List<Subscriber> getSubsribers(){
        EnumSet<Application> apps = EnumSet.noneOf(Application.class);
        apps.add(Application.PREDAL);
        apps.add(Application.DNS);
        log.info("apps={}", apps);
        return subscriberRepo.findByAppsIn(apps); // <-- bug
    }
}
  • No compiler errors, but runtime error!!
  • log:
21-10-2020 12:49:12.532 [http-nio-8881-exec-4] INFO  s.a.r.service.SubscriberService.getSubsribers(27) - apps=[DNS, PREDAL]
21-10-2020 12:49:12.533 [http-nio-8881-exec-4] ERROR s.a.r.e.ResourcesExceptionHandler.generalException(51) - error msg=Parameter value [DNS] did not match expected type [java.util.EnumSet (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [DNS] did not match expected type [java.util.EnumSet (n/a)]
21-10-2020 12:49:12.534 [http-nio-8881-exec-4] WARN  o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver.logException(199) - Resolved [org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [DNS] did not match expected type [java.util.EnumSet (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [DNS] did not match expected type [java.util.EnumSet (n/a)]]
  • It seems it see only one element in EnumSet and also it is casting it to an array

Regards

Comment From: snicoll

Thanks for the report but the caps aren't really necessary. There is nothing in this report (or the stacktrace) that points to a problem with Spring Boot. Rather it is a JPA mapping problem for which we can't provide you support here unfortunately. There are a number of questions on StackOverflow regarding persisting enums (for instance this one) so please follow-up there.

Comment From: sysmat

You are pointing to column type ENUM I'm pointing of type SET column with enums, this is totally different. So you are saying the bug is in Hibernate 5.4.21.Final but this is clearly not TRUE in log it is clearly bug in org.springframework.dao it cast EnumSet to array with last value from Enumset, when I'll have time I'll show you where is BUG in source code

Comment From: sysmat

By the way native query works, JpaRepository clearly not

Comment From: philwebb

I don't think this is a bug.

You are defining Subscriber to have an EnumSet<Application> field and then asking Spring Data to generate a query from List<Subscriber> findByAppsIn(EnumSet<Application> apps) which it can't do.

You probably need to either use List<Subscriber> findByApps(EnumSet<Application> apps) or List<Subscriber> findByAppsIn(Set<EnumSet<Application>> apps) depending on what it is you're trying to do.

I'd suggest asking a new question on stackoverflow.com and providing a bit more background about your actual problem. You'll probably get a better response if you provide a sample application and include the full stacktrace.

We can't give any further support here I'm afraid.