java - Hibernate Criteria : Find property nested in a list -
im trying build using criteriabuilder following query :
select * job j, asset a, asset_users au j.job_id = a.asset_id , a.asset_id = au.asset_id , au.user_id = 6
where job has asset , asset has list of users... want return list of jobs have asset contains given user...
i saw guys doing :
session session = this.sessionfactory.getcurrentsession(); criteria criteria = session.createcriteria(company.class); criterion = restrictions.eq("companyroles.name", "admin"); criteria.add(criterion); list<company> companylist = criteria.list();
tried replicate criteriabuilder got no luck. getting couldn't find user id inside object list (userlist). guess example harder because have access object (job).asset.userlist.id . btw, tried :
criteriabuilder cb = em.getcriteriabuilder(); criteriaquery<job> cq = cb.createquery(job.class); root<job> jobroot = cq.from(job.class); join<job, user> assetjoin = jobroot.join("asset.userlist"); cq.where(assetjoin.get("id").in(id));
got same issue... couldn't find path.
any appreciated! thanks
i think missing step. need next level of joining.
criteriabuilder cb = em.getcriteriabuilder(); criteriaquery<job> cq = cb.createquery(job.class); root<job> jobroot = cq.from(job.class); // join asset join<job, asset> assetjoin = jobroot.join("asset"); // join list of users join<asset, user> assetuserjoin = assetjoin.join("userlist"); cq.where(assetuserjoin.get("id").in(id));
the type of assetusrjoin.get("id")
path<long>
or similar. jpa criteria api
Comments
Post a Comment