Thursday, 15 March 2012

java ee - Select with JOINED Inhertiance leads to no results -



java ee - Select with JOINED Inhertiance leads to no results -

maybe overlooking crucial when working jpa/eclipselink (postgresql 9.2) , inheritancestrategy.joined not create sense me.

i have hierarchy this:

@entity @inheritance(strategy = inheritancetype.joined) @classextractor(projectclassextractor.class) public class project extends abstractentity { @manytoone company c; }

and entity

@entity @inheritance(strategy = inheritancetype.joined) public class morespecificproject extends project { }

i seek query projects (including morespecificprojects) assigned company given set of companies.

the criteria code follows:

public list<project> getprojectswithcompany(company company) { criteriabuilder cb = getentitymanager().getcriteriabuilder(); criteriaquery<project> query = cb.createquery(project.class); root<project> projectroot = query.from(project.class); query.select(projectroot); query.where(cb.equal(projectroot.get(project_.c), company)); query.distinct(true); homecoming getentitymanager().createquery(query).getresultlist(); }

i have 1 project in database , morespecificproject table empty. project has company c set properly.

now eclipselink (glassfish4.0) produces next sql (remark: removed long list of irrelevant columns):

select distinct t0.*, t1.* project t0, morespecificproject t1 ((t0.c_id= 664) , (t0.id=t1.id))

obviously returns no result, since there no matching entry in morespecificproject. should homecoming 1 project in project table.

how eclipselink generate proper sql (e.g. using left bring together on morespecificproject)?

please help me on one.

thanks in advance.

edit: found out if limit result

typedquery<project> tquery = entitymanager. createquery(query); tquery.setfirstresult(0).setmaxresults(5); homecoming tquery.getresultlist();

the right sql beeing created:

select t0.*, t1.* project t0 left outer bring together morespecificproject t1 on (t1.id = t0.id) (t0.c_id = 664) limit 5 offset 0

and resultin list contains right project. why limiting result set, lead right query criteria api? may bug?

according http://wiki.eclipse.org/eclipselink/userguide/jpa/basic_jpa_development/entities/inheritance#outer_joining_subclasses default query subclasses , bring together results in memory. should see query each class returned, not morespecificproject class.

java-ee jpa eclipselink glassfish-4

No comments:

Post a Comment