java - Hibernate: how to use Left Join -


let's suppose have 2 tables: tablea , tableb. tablea , tableb in @onetoone relation on 2 field (fielda1 , fielda2 on fieldb1 , fieldb2) , relation not exist instances of tablea.

what hibernate have occurrences of tablea have or not relation occurrences tableb. that, have use left join.

considering tablea's entity has property "tableb" of tableb's entity declared annotation @onetoone, how create query?

is correct query?

select tablea left join fetch a.tableb

my problem query when rows of tablea doesn't have match row of tableb, hibernate throw exception depends on annotations (fetch = eager or lazy) used.

i post code more clear:

@entity @table(name = "table_a") public class tablea extends evoluzionestati implements serializable {      private static final long serialversionuid = 1l;      @onetoone     @joincolumns({         @joincolumn(name = "id", referencedcolumnname = "id", insertable=false, updatable=false),         @joincolumn(name = "num", referencedcolumnname = "num", insertable=false, updatable=false) })     private tableb tableb; other code here... 

if use lazy annotation, query processes ok when try access tableb object check if null, exception of lazyinitialization occurs . instead when use eager annotation, throws exception during processing query because occurrences of tablea not have match in tableb. precise can't initialize hibernate session when query result because of project composition , configuration.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -