0

I 'd like to convert the query below to hql to return me a List<Article> because with createSqlQuery it is impossible , I must convert the result manually :
here is the sql query :

Query query = getSessionFactory().getCurrentSession().createSQLQuery(
                 "select * 
                  from article 
                  where articleID in (select articleID 
                                      from article_depot 
                                      where depotID = "+depotID+")"
              );

thank you in advance

1 Answer 1

2

Assuming that you have a OneToMany relation between article_depot and article (One Depot contains multiple articles) if this have been correctly mapped the query would be :

Query query = getSessionFactory().getCurrentSession().createQuery("SELECT d.article from article_depot d where d.depotId = :depotId");
query.setParameter("depotId", depotId);
List<article> resultList = query.getResultList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.