Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

mysql - Java Criteria Query with Hibernate - generated alias invalid path?

I have the following java code that uses hibernate predicates to return search reusults from my Appointment MYSQL table.

public List<Appointment> getSearchResults(String client, AppointmentSearchRequest searchRequest, Predicate completePredicate) {

    List<Appointment> searchResults = new ArrayList<>();
    EntityManager entityManager = null;

    try {
        entityManager = entityManagement.createEntityManager(client);
        CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        CriteriaQuery<Appointment> query = builder.createQuery(Appointment.class);
        Root<Appointment> from = query.from(Appointment.class);
        CriteriaQuery<Appointment> selectQuery = query.select(from);
        selectQuery = selectQuery.where(completePredicate);

        searchResults = entityManager.createQuery(selectQuery).setFirstResult(searchRequest.getIndex()).setMaxResults(searchRequest.getSize()).getResultList();
    }catch (Exception e){
       //
    }

    return searchResults;
}

When I run this code, at the following line:

searchResults = entityManager.createQuery(selectQuery).setFirstResult(searchRequest.getIndex()).setMaxResults(searchRequest.getSize()).getResultList();

I am getting the error:

17:20:27,730 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (http-/127.0.0.1:8080-2) Invalid path: 'generatedAlias1.title'
17:20:27,734 ERROR [org.hibernate.hql.internal.ast.ErrorCounter] (http-/127.0.0.1:8080-2) Invalid path: 'generatedAlias1.title':  Invalid path: 'generatedAlias1.title'
    at org.hibernate.hql.internal.ast.util.LiteralProcessor.lookupConstant(LiteralProcessor.java:119) [hibernate-core-4.2.7.SP1-redhat-3.jar:4.2.7.SP1-redhat-3]

What could be causing this error?

question from:https://stackoverflow.com/questions/65942200/java-criteria-query-with-hibernate-generated-alias-invalid-path

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try checking your Query

See this answer. It might be just as simple as checking your query aliases. Make sure that they match, otherwise the query won't compile at all. You didn't list your full query here, so I can't tell if it's incorrect or not.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...