简体   繁体   中英

java.lang.IllegalArgumentException: Error occurred validating the Criteria

I'm using webflux and hibernate reactive , and my findAll methosd doesn't work, thrown exception: java.lang.IllegalArgumentException: Error occurred validating the Criteria

i debuged it and i found out that it throws exception in this part:

session.createQuery(criteria)

public Flux<MyrUser> findAll(Integer offsetResult, Integer numberMaxResults) {

    try {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("my-persistence-unit");
        Mutiny.SessionFactory factory = emf
                .unwrap(Mutiny.SessionFactory.class);

        CriteriaBuilder builder = factory.getCriteriaBuilder();
        CriteriaQuery<MyrUser> criteria = builder.createQuery(MyrUser.class);

        Flux<MyrUser> myUser= Flux.fromIterable(
                factory.withSession(
                        session -> {
                            return session
                                    .createQuery(criteria)
                                    .setFirstResult(offsetResult)
                                    .setMaxResults(numberMaxResults)
                                    .getResultList();
                        }).await().indefinitely());
        factory.close();
        return myUser;
    } catch (Exception exception) {
        log.error(exception);
        return Flux.empty();
    }}

If the incoming type is of type TextMessage then of course you cannot cast it to an ObjectMessage as that is not the correct type as TextMessage does not implement the ObjectMessage interface. You need to use type checks to determine what type of message you are dealing with and perform the correct casts.

if (message instanceof ObjectMessage) {
} else if message instanceof TextMessage) {
} // etc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM