I have deux tables in my datables. The Account
table and the AccountType
table. I need a JPQL query to retrieve all accounts with column kind (in table AccountType
) equal "BalanceSheet", I also need another one to retrieve all accounts witch the column kind(in table AccountType) equal "Outturn".
I try this put the don't works.
Query query = daoFactory
.getEntityManager()
.createQuery(
"SELECT a FROM Account a WHERE a.deleted=false AND a.type_id IN (SELECT id FROM "
+ "AccountType WHERE deleted=false AND kind='BalanceSheet')");
List<Account> result = query.getResultList();
It looks like you forgot to give a identification variable
to your AccountType
entity.
SELECT a
FROM Account a
WHERE a.deleted=false
AND a.type_id IN (SELECT at.id FROM AccountType at
WHERE at.deleted=false
AND at.kind= 'BalanceSheet')
See also:
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.