java - JPA CriteriaQuery join three tables not directly navigable -


i need translate sql query jpa criteria:

select tbl1.id_t1, tbl2.name, tbl3.name, tbl4.symbol, tbl1.limit, tbl1.value, tbl1.uncertainty  table_1 tbl1 join table_2 tbl2 on tbl2.id_t2=tbl1.id_t2 join table_3 tbl3 on tbl3.id_t3=tbl1.id_t3 join table_4 tbl4 on tbl4.id_t4=tbl1.id_t4 (tbl2.id_l=1 , tbl3.id_l=1) , tbl1.id_s=1; 

my mapping between pojo , database table follows:

table_1

@entity @table("table_1") public class table1 {  @id  @column(name="id_t1")  private long idrowt1  @manytoone  @joincolumn(name="id_t2")  private table2 tbl2;  @manytoone  @joincolumn(name="id_t3")  private table3 tbl3;  @manytoone  @joincolumn(name="id_t4")  private table4 tbl4;  @column(name="limit")  private string limit;  @column(name="value")  private string value;  @column(name="uncertainty")  private string uncertainty;   // getter , setter } 

table_2

@entity @table("table_2") public class table2 {  @id  @column(name="id_t2")  private long idt2;   // getter , setter } 

table_2_lang

@entity @table("table_2_lang") @idclass(table2langpk.class) public class table2lang {  @id  @column(name="id_t2")  private long idt2;  @id  @column(name="id_l")  private lang l;  @column(name="name")  private string name;   // getter , setter } 

table_3

@entity @table("table_3") public class table3 {  @id  @column(name="id_t3")  private long idt3;   // getter , setter } 

table_3_lang

@entity @table("table_3_lang") @idclass(table3langpk.class) public class table3lang {  @id  @column(name="id_t3")  private long idt3;  @id  @column(name="id_l")  private lang l;  @column(name="name")  private string name;   // getter , setter } 

table_4

@entity @table("table_4") public class table4 {  @id  @column(name="id_t4")  private long idt4;  @column(name="name")  private string name;   // getter , setter } 

to send data business layer front-end i'm using value objects defined follows:

simple entity

public class simpleentityvo {  private long entityid;  private string name;   // getter , setter } 

complex entity

public class simpleentityvo {  private long entityid;  private simpleentityvo tbl2vo;  private simpleentityvo tbl3vo;  private simpleentityvo tbl4vo;  // ... other field of table_1   // getter , setter } 

in ejb need implement method return list of complexentityvo starting table_1

...  private criteriabuilder cb = em.getcriteriabuilder();  public list<complexentityvo> findall(long id_s, long id_l) {  criteriaquery<complexentityvo> cq = cb.createquery(complexentityvo.class)  root<table1> tbl1root = cq.from(table1.class);   // update begin  root<table2lang> tbl2root = cq.from(table2lang.class);  ...   selection<simpleentityvo> sestbl2 = cb.construct(simpleentityvo.class, tbl2root.get(table2lang_.id_t2), tbl2root.get(table2lang_.name));   // selection table_3_lang , table_4 same  // update end   typedquery<complexentityvo> tq = em.createquery(cq); }  ... 

to achieve results i've tried join betwen table1 , table2lang, tried selection 1 exposed below

`selection<simpleentityvo> ses = cb.construct(simpleentityvo.class, ...);` 

using root lang table, tried solution exposed here

https://community.oracle.com/message/10795956#10795956

but when try execute statement

`cq.select(cb.construct(complexentityvo.class, id_t1, simpleentityvo)` 

or this

`cq.multiselect(...)` 

i the: illegalargumentexception

caused by: org.hibernate.hql.internal.ast.querysyntaxexception: unexpected token: , near line 1, column 64 [select new com.example.vo.complexentityvo(generatedalias0.id_t1,  new com.example.labims.vo.simpleentityvo(generatedalias1.table2.id_t2, generatedalias1.name),  new com.example.vo.simpleentityvo(generatedalias2.table_3.id_t3, generatedalias2.name),  new com.example.vo.simpleentityvo(generatedalias3.id_t4, generatedalias3.name),  generatedalias0.limit, generatedalias0.value, generatedalias0.uncertainty)  com.example.table1 generatedalias0,   com.example.model.table2lang generatedalias1,   com.example.model.table3lang generatedalias2,  com.example.model.table4 generatedalias3  ( generatedalias0.id_s=:param0 ) , ( ( generatedalias1.lang.id_l=:param1 ) , ( generatedalias2.lang.id_l=:param1 ) )] 

from cause of execption understanded can't instanciate new object inside select or multiselect statement, don't find way achieve original sql query using criteria api.

update i've added excerpt of i've tried achieve result between //update begin , //update end

i think make hibernate show sql == true , take query console,test showed query databases , find error hbernate not generate query correct


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -