Skip to content
Advertisement

Creating dynamic query using jpa criteria

I created dynamic query using jpa criteria but an extra pair of parentheses gets added to columns to be selected when I do userGroupSubquery.select(userGroupsRoot);

generated query

select (securitygr3_.group_name, securitygr3_.user_name) from gm.security_groupings securitygr3_ where 1=1 and securitygr3_.user_name=’xxx’ and (securitygr3_.group_name in (‘XYZ’))

expected query:

select securitygr3_.group_name, securitygr3_.user_name from gm.security_groupings securitygr3_ where 1=1 and securitygr3_.user_name=’xxx’ and (securitygr3_.group_name in (‘XYZ’))

Its just that I get an extra pair of parentheses at select (securitygr3_.group_name, securitygr3_.user_name) from which gives me ora-00907 missing right parenthesis error. I am sure it is coming from userGroupSubquery.select(userGroupsRoot) but I am not sure why. Please help

Advertisement

Answer

I got the solution for the above. When the entity has a composite key, then in JPA criteria instead of doing

we should do

where id is the composite id.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement