java - Bidirectional OneToMany @LazyCollection(LazyCollectionOption.EXTRA) -
i have problem lazycollection.
guy on site lazy collection tutorial says
hibernate not materialize collection elements when accessing collection , inserting collection (at least in example of winery , wine onetomany relationship mapping)
but doesn't working me.
here entities:
import javax.persistence.*; import javax.persistence.entity; import javax.persistence.table; import java.util.arraylist; import java.util.date; import java.util.list; @entity @table(name="document_generated") public class documentdomaintogenerateimpl extends domainobjectimpl<documentdomaintogenerate, integer> implements documentdomaintogenerate{ /** * */ private static final long serialversionuid = -1297116626347796196l; private string identificationkey; private identification identification; private string documentgroup; private string documenttype; private server server; private int statusorder = 2; private int numberofattempt; private auditdata auditdata; private date documentissuancedate; private date creationdate; private documentstatus documentcurrentstate; private list<documentgeneratedhistorystatus> documentgeneratedhistorystatuslist = new arraylist<documentgeneratedhistorystatus>(4); public string getidentificationkey() { return identificationkey; } public void setidentificationkey(string identificationkey) { this.identificationkey = identificationkey; } @embedded @target(auditdataimpl.class) public auditdata getauditdata() { return auditdata; } public void setauditdata(auditdata auditdata) { this.auditdata = auditdata; } @embedded @target(identificationimpl.class) @attributeoverrides({ @attributeoverride(name = "businessid", column = @column(name = "business_id_doc")), @attributeoverride(name = "businessidcontextname", column = @column(name = "business_id_ctx_doc")), @attributeoverride(name = "identificationid", column = @column(name = "id_doc")), @attributeoverride(name = "identificationidcontextname", column = @column(name = "id_ctx_name_doc")) }) public identification getidentification() { return identification; } public void setidentification(identification identification) { this.identification = identification; } public int getstatusorder() { return statusorder; } public void setstatusorder(int statusorder) { this.statusorder = statusorder; } public string getdocumentgroup() { return documentgroup; } public void setdocumentgroup(string documentgroup) { this.documentgroup = documentgroup; } public string getdocumenttype() { return documenttype; } public void setdocumenttype(string documenttype) { this.documenttype = documenttype; } public int getnumberofattempt() { return numberofattempt; } public void setnumberofattempt(int numberofattempt) { this.numberofattempt = numberofattempt; } @embedded @target(serverimpl.class) public server getserver() { return server; } public void setserver(server server) { this.server = server; } @embedded @target(documentstatusimpl.class) public documentstatus getdocumentcurrentstate() { return documentcurrentstate; } public void setdocumentcurrentstate(documentstatus documentcurrentstate) { this.documentcurrentstate = documentcurrentstate; } @temporal(temporaltype.timestamp) public date getdocumentissuancedate() { return documentissuancedate; } public void setdocumentissuancedate(date documentissuancedate) { this.documentissuancedate = documentissuancedate; } @temporal(temporaltype.timestamp) public date getcreationdate() { return creationdate; } public void setcreationdate(date creationdate) { this.creationdate = creationdate; } @onetomany(fetch = fetchtype.lazy, targetentity = documentgeneratedhistorystatusimpl.class) @cascade(cascadetype.all) @jointable(name = "doc_gen_status", joincolumns = {@joincolumn(name="doc_gen_id")}, inversejoincolumns = {@joincolumn(name = "doc_gen_stat_id")}) @indexcolumn(name="doc_gen_id_index", base = 1) @lazycollection(lazycollectionoption.extra) public list<documentgeneratedhistorystatus> getdocumentgeneratedhistorystatuslist() { return documentgeneratedhistorystatuslist; } public void setdocumentgeneratedhistorystatuslist( list<documentgeneratedhistorystatus> documentgeneratedhistorystatuslist) { this.documentgeneratedhistorystatuslist = documentgeneratedhistorystatuslist; } @override public boolean equals(object o) { if (this == o) return true; if (!(o instanceof documentdomaintogenerateimpl)) return false; documentdomaintogenerateimpl = (documentdomaintogenerateimpl) o; return new equalsbuilder() .appendsuper(super.equals(o)) .append(getstatusorder(), that.getstatusorder()) .append(getnumberofattempt(), that.getnumberofattempt()) .append(getidentificationkey(), that.getidentificationkey()) .append(getidentification(), that.getidentification()) .append(getdocumentgroup(), that.getdocumentgroup()) .append(getdocumenttype(), that.getdocumenttype()) .append(getserver(), that.getserver()) .append(getauditdata(), that.getauditdata()) .append(getdocumentissuancedate(), that.getdocumentissuancedate()) .append(getcreationdate(), that.getcreationdate()) .append(getdocumentcurrentstate(), that.getdocumentcurrentstate()) .isequals(); } @override public int hashcode() { return new hashcodebuilder(17, 37) .appendsuper(super.hashcode()) .append(getidentificationkey()) .append(getidentification()) .append(getdocumentgroup()) .append(getdocumenttype()) .append(getserver()) .append(getstatusorder()) .append(getnumberofattempt()) .append(getauditdata()) .append(getdocumentissuancedate()) .append(getcreationdate()) .append(getdocumentcurrentstate()) .tohashcode(); }
second entity:
import javax.persistence.embedded; import javax.persistence.entity; import javax.persistence.manytoone; import javax.persistence.table; @entity @table(name="doc_gen_hist_status") public class documentgeneratedhistorystatusimpl extends domainobjectimpl<documentgeneratedhistorystatus, integer> implements documentgeneratedhistorystatus{ /** * */ private static final long serialversionuid = -8542541552897795870l; private documentstatus documentstatus; private documentdomaintogenerate documentdomaintogenerate; @embedded @target(documentstatusimpl.class) public documentstatus getdocumentstatus() { return documentstatus; } public void setdocumentstatus(documentstatus documentstatus) { this.documentstatus = documentstatus; } @override @manytoone(targetentity = documentdomaintogenerateimpl.class) public documentdomaintogenerate getdocumentdomaintogenerate() { return documentdomaintogenerate; } @override public void setdocumentdomaintogenerate(documentdomaintogenerate documentdomaintogenerate) { this.documentdomaintogenerate = documentdomaintogenerate; } @override public boolean equals(object o) { if (this == o) return true; if (!(o instanceof documentgeneratedhistorystatusimpl)) return false; documentgeneratedhistorystatusimpl = (documentgeneratedhistorystatusimpl) o; return new equalsbuilder() .appendsuper(super.equals(o)) .append(getdocumentstatus(), that.getdocumentstatus()) .isequals(); } @override public int hashcode() { return new hashcodebuilder(11, 61) .appendsuper(super.hashcode()) .append(getdocumentstatus()) .tohashcode(); }
}
and when i'm loading documentdomaintogenerate following sql executed:
select this_.id id25_0_, this_.business_id_app business2_25_0_, this_.business_id_ctx_app business3_25_0_, this_.id_app id4_25_0_, this_.id_ctx_name_app id5_25_0_, this_.modulename modulename25_0_, this_.business_id_app_role business7_25_0_, this_.business_id_ctx_app_role business8_25_0_, this_.id_app_role id9_25_0_, this_.id_ctx_name_app_role id10_25_0_, this_.business_id_app_user business11_25_0_, this_.business_id_ctx_app_user business12_25_0_, this_.id_app_user id13_25_0_, this_.id_ctx_name_app_user id14_25_0_, this_.creationdate creatio15_25_0_, this_.doc_stat_app_b_id doc16_25_0_, this_.doc_stat_app_b_id_ctx doc17_25_0_, this_.doc_stat_app_id doc18_25_0_, this_.doc_stat_app_id_ctx doc19_25_0_, this_.doc_stat_app_module_name doc20_25_0_, this_.doc_stat_role_b_id doc21_25_0_, this_.doc_stat_role_b_id_ctx doc22_25_0_, this_.doc_stat_role_id doc23_25_0_, this_.doc_stat_role_id_ctx doc24_25_0_, this_.doc_stat_user_b_id doc25_25_0_, this_.doc_stat_user_b_id_ctx doc26_25_0_, this_.doc_stat_user_id doc27_25_0_, this_.doc_stat_user_id_ctx doc28_25_0_, this_.description descrip29_25_0_, this_.effectivedatetime effecti30_25_0_, this_.ordertosend orderto31_25_0_, this_.sended sended25_0_, this_.statuscode_id statuscode45_25_0_, this_.documentgroup documen33_25_0_, this_.documentissuancedate documen34_25_0_, this_.documenttype documen35_25_0_, this_.business_id_doc business36_25_0_, this_.business_id_ctx_doc business37_25_0_, this_.id_doc id38_25_0_, this_.id_ctx_name_doc id39_25_0_, this_.identificationkey identif40_25_0_, this_.numberofattempt numbero41_25_0_, this_.ip ip25_0_, this_.nodepid nodepid25_0_, this_.statusorder statuso44_25_0_ document_generated this_ this_.id = ?
next need add new documentgeneratedhistorystatus list in documentdomainttogenerate , when i'm executing this
documentgeneratedhistorystatus.setdocumentdomaintogenerate(documentdomaintogenerate); documentdomaintogenerate.getdocumentgeneratedhistorystatuslist().add(documentgeneratedhistorystatus);
this sql executed
select documentge0_.doc_gen_id doc1_25_2_, documentge0_.doc_gen_stat_id doc2_2_, documentge0_.doc_gen_id_index doc3_2_, documentge1_.id id10_0_, documentge1_.documentdomaintogenerate_id documen19_10_0_, documentge1_.doc_stat_app_b_id doc2_10_0_, documentge1_.doc_stat_app_b_id_ctx doc3_10_0_, documentge1_.doc_stat_app_id doc4_10_0_, documentge1_.doc_stat_app_id_ctx doc5_10_0_, documentge1_.doc_stat_app_module_name doc6_10_0_, documentge1_.doc_stat_role_b_id doc7_10_0_, documentge1_.doc_stat_role_b_id_ctx doc8_10_0_, documentge1_.doc_stat_role_id doc9_10_0_, documentge1_.doc_stat_role_id_ctx doc10_10_0_, documentge1_.doc_stat_user_b_id doc11_10_0_, documentge1_.doc_stat_user_b_id_ctx doc12_10_0_, documentge1_.doc_stat_user_id doc13_10_0_, documentge1_.doc_stat_user_id_ctx doc14_10_0_, documentge1_.description descrip15_10_0_, documentge1_.effectivedatetime effecti16_10_0_, documentge1_.ordertosend orderto17_10_0_, documentge1_.sended sended10_0_, documentge1_.statuscode_id statuscode20_10_0_, documentdo2_.id id25_1_, documentdo2_.business_id_app business2_25_1_, documentdo2_.business_id_ctx_app business3_25_1_, documentdo2_.id_app id4_25_1_, documentdo2_.id_ctx_name_app id5_25_1_, documentdo2_.modulename modulename25_1_, documentdo2_.business_id_app_role business7_25_1_, documentdo2_.business_id_ctx_app_role business8_25_1_, documentdo2_.id_app_role id9_25_1_, documentdo2_.id_ctx_name_app_role id10_25_1_, documentdo2_.business_id_app_user business11_25_1_, documentdo2_.business_id_ctx_app_user business12_25_1_, documentdo2_.id_app_user id13_25_1_, documentdo2_.id_ctx_name_app_user id14_25_1_, documentdo2_.creationdate creatio15_25_1_, documentdo2_.doc_stat_app_b_id doc16_25_1_, documentdo2_.doc_stat_app_b_id_ctx doc17_25_1_, documentdo2_.doc_stat_app_id doc18_25_1_, documentdo2_.doc_stat_app_id_ctx doc19_25_1_, documentdo2_.doc_stat_app_module_name doc20_25_1_, documentdo2_.doc_stat_role_b_id doc21_25_1_, documentdo2_.doc_stat_role_b_id_ctx doc22_25_1_, documentdo2_.doc_stat_role_id doc23_25_1_, documentdo2_.doc_stat_role_id_ctx doc24_25_1_, documentdo2_.doc_stat_user_b_id doc25_25_1_, documentdo2_.doc_stat_user_b_id_ctx doc26_25_1_, documentdo2_.doc_stat_user_id doc27_25_1_, documentdo2_.doc_stat_user_id_ctx doc28_25_1_, documentdo2_.description descrip29_25_1_, documentdo2_.effectivedatetime effecti30_25_1_, documentdo2_.ordertosend orderto31_25_1_, documentdo2_.sended sended25_1_, documentdo2_.statuscode_id statuscode45_25_1_, documentdo2_.documentgroup documen33_25_1_, documentdo2_.documentissuancedate documen34_25_1_, documentdo2_.documenttype documen35_25_1_, documentdo2_.business_id_doc business36_25_1_, documentdo2_.business_id_ctx_doc business37_25_1_, documentdo2_.id_doc id38_25_1_, documentdo2_.id_ctx_name_doc id39_25_1_, documentdo2_.identificationkey identif40_25_1_, documentdo2_.numberofattempt numbero41_25_1_, documentdo2_.ip ip25_1_, documentdo2_.nodepid nodepid25_1_, documentdo2_.statusorder statuso44_25_1_ doc_gen_status documentge0_ inner join doc_gen_hist_status documentge1_ on documentge0_.doc_gen_stat_id=documentge1_.id left outer join document_generated documentdo2_ on documentge1_.documentdomaintogenerate_id=documentdo2_.id documentge0_.doc_gen_id=?
is there option don't fetch whole collection when i'm trying add new item collection? doin'g wrong?
Comments
Post a Comment