Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - Hibernate HQL issue expecting IDENT found "*"

I need to go whole datas from relative table so I'm using somethink like this (i would use it in sql)

    private static final String SELECT_OOPR_TO_SEND = "SELECT R.* " +
                                                      "FROM offerOrderProjectRel R, offerOrder O, project P " +
                                                      "WHERE P.id = R.project_id and O.id = R.offer_order_id " +
                                                      "and O.type = 'ORDER' and (P.status = 'PENDING' or P.status ='PROTECTED')" ;
; 


    @SuppressWarnings("unchecked")
    public List<OfferOrderProjectRel> findAllOfferOrderToSendToSalesmans() {
        Query q = getSession().createQuery(SELECT_OOPR_TO_SEND);
        List<OfferOrderProjectRel> list = q.list();
        return list;
    }

After lauching this code i'm getting that error :

org.hibernate.hql.internal.ast.QuerySyntaxException: expecting IDENT, found '*' near line 1, column 10 [SELECT R. FROM offerOrderProjectRel R, offerOrder O, project P WHERE P.id = R.project_id and O.id = R.offer_order_id and O.type = 'ORDER' and (P.status = 'PENDING' or P.status ='PROTECTED')]

So how can i obtain all datas from column R with hibernate?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

The method createQuery expects an HQL query string.

HQL is an object-oriented querying language.

HQL interprets SELECT R.* as select the member field * of the object R.

But * is not a member field of R. Is it?..

To select all the member fields of R use:

SELECT R
FROM offerOrderProjectRel R, offerOrder O, project P
WHERE P.id = R.project_id and O.id = R.offer_order_id
and O.type = 'ORDER' and (P.status = 'PENDING' or P.status ='PROTECTED')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...