java - How to Inner Join Two Independent Entities in Hibernate -


i have 2 entities: documententity (docnumber (primary key), dateoffill, ...) , fileentity (id, title, size, ...). have hql query inner join of 2, should run on oracle db:

string querystr = "select docnumber " +              + "from documententity d " +              + "inner join fileentity f " +              + "on d.docnumber = f.title " +              + "where d.date > to_date('01.01.2011','dd.mm.yyyy')"  query query = em.createquery(query_string); return query.getresultlist(); 

when run code snippet i'm getting exception org.hibernate.hql.ast.querysyntaxexception: path expected join!

i looked through

but none resolved problem. suggested paths cannot used in example (at least gives wrong path error). answer of last link says that:

joins can used when there association between entities.

the issue cannot associate these 2 entities.

the question is: how can join these 2 entities?

update: entities are:

@entity @table(name = "document") public class documententity implements serializable {      private static final long serialversionuid = 1l;      @id     @column(name = "doc_number", nullable = false)     private string docnumber;      @basic(optional = false)     @column(name = "date_of_fill")     @temporal(temporaltype.date)     private date dateoffill;      ... } 

and

@entity @table(name = "fs_file") public class fileentity implements serializable {      private static final long serialversionuid = 1l;      @id     @sequencegenerator(name = "fs_file_seq", allocationsize = 1, sequencename = "fs_file_seq")     @generatedvalue(strategy = generationtype.sequence, generator = "fs_file_seq")     @column(name = "id", nullable = false)     protected long id;      @column(name = "title", nullable = false)     protected string title;      @column(name = "mimetype", nullable = false)     protected string mimetype;      @column(name = "filesize", nullable = false)     protected long filesize;      @column(name = "filepath", nullable = false)     protected string filepath;      ... } 

in case, don't need join since limit result condition d.docnumber = f.title. add condition in clause , use sql query instead of jpql query since seems more matching need.

string sqlstring= "select d.docnumber " +              + "from document d, fs_file f " +              + "where d.docnumber = f.title " +              + "and d.date > to_date('01.01.2011','dd.mm.yyyy')"   query query = em.createnativequery(sqlstring); return query.getresultlist(); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -