sql - What is wrong with JPQL (count and select) -


below query rows parent table , count of each id child table.

@query("select cnt idcount, person person person,(select count(child.id) cnt child child child.id :input_id) idcount person.id :input_id") list<person> searchpersonwithcount(@param("input_id") long input_id); 

i below error:

caused by: org.hibernate.hql.internal.ast.querysyntaxexception: unexpected token: idcount near line 1, column 12 [select cnt idcount, person com.myc.cc.domain.person person,(select count(child.id) cnt com.myc.cc.domain.child child child.id :input_id) idcount person.id :input_id]     @ org.hibernate.hql.internal.ast.querysyntaxexception.convert(querysyntaxexception.java:54) 

when execute in oracle sqldeveloper able results.

native query executed in qracle sql developer:

select  cnt idcount, person.* person person,(select count(*) cnt child child id = '1235') idcount id = '1235' 

result:

idcount         id          name    2          1235         persona 

can please let me know wrong in jpql.

thanks in advance.

sample data :

parent table:

id         name  1001      samplenamea 1002      samplenameb 1003      samplenamec 

child table:

id        name       interests  1001     samplenamea    music    1001     samplenamea    dance 1001     samplenamea    coding 1003     samplenamec    music    1002     samplenameb    dance 1002     samplenameb    coding 

if id = 1001,

expected output

count   id         name  3   1001      samplenamea 


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -