java - Lazy Initialiazation Exception in Child collections -


i have entity class below

@table(name = "parent") public class parent implements comparable<parent>, serializable, cloneable { @id @generatedvalue(strategy = generationtype.auto, generator = "seq-gen") @genericgenerator(name = "seq-gen", strategy = "native",         parameters = {@parameter(name = "sequence_name", value = "id_seq")}) private long id;   @onetomany(mappedby = "parent", cascade = cascadetype.all) @batchsize(size = 50)    @sortnatural private sortedset<child> child  = new treeset<>();  @onetomany(mappedby = "parent", cascade = cascadetype.all) @batchsize(size = 50)    @sortnatural private sortedset<child> child  = new treeset<>();  @onetomany(mappedby = "parent", cascade = cascadetype.all) @batchsize(size = 50)    @sortnatural private sortedset<second> second = new treeset<>();  

}

and child entity below

@entity @table(name = "child")  public class child implements comparable<object>, serializable, cloneable {  @id @generatedvalue(strategy = generationtype.auto, generator = "seq-gen") @genericgenerator(name = "seq-gen", strategy = "native",         parameters = {@parameter(name = "sequence_name", value = "child_id_seq")}) private long id;  @manytoone() @fetch(fetchmode.select) @joincolumn(name = "parentid", nullable = false) private parent parent; 

}

i calling child in service method session

public child getchild(final long id,) throws exception {     try {         child child = (child) gethibernatetemplate().execute(new hibernatecallback<child>() {              /* (non-javadoc)              * @see org.springframework.orm.hibernate5.hibernatecallback#doinhibernate(org.hibernate.session)              */             public child doinhibernate(session session) throws hibernateexception {                  child child = (child)session.get(child.class, id);                  if(child != null) {                     parent parent = child.parent();                      if(step.getparent() != null) {                         hibernate.initialize(parent);                         if (parent.getsecond () != null) {                             hibernate.initialize(parent.getsecond());                         }                     }                                                        }             }         }     } } 

i getting lazy initialization exception @

if (parent.getsecond () != null) {

i have tried adding

@fetch(fetchmode.select)

in both parent , child classes, no success , have strict rule not use eager. please me solve above issue.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -