java - Envers: error mapping a collection with deleted entities -
we using hibernate envers full data entity , related entities in date. , problem error when accessing items collection deleted after moment. seems problem because accessing db retrieve entities doesn't exist anymore.
this main entity:
@xmltype @xmlrootelement @entity @audited @table(name = payrollentity.table_name) @namedqueries({ @namedquery(name = payrollentity.exists_by_id_query_name, query = payrollentity.exists_by_id_query, hints = {@queryhint(name = "org.hibernate.cacheable", value = "true")}), @namedquery(name = payrollentity.find_payroll_query_name, query = payrollentity.find_payroll_query, hints = {@queryhint(name = "org.hibernate.cacheable", value = "true")}), @namedquery(name = payrollentity.find_extrapay_query_name, query = payrollentity.find_extrapay_query, hints = {@queryhint(name = "org.hibernate.cacheable", value = "true")}), @namedquery(name = payrollentity.find_payrolls_by_employment_query_name, query = payrollentity.find_payrolls_by_employment_query, hints = {@queryhint(name = "org.hibernate.cacheable", value = "true")}), }) public class payrollentity extends abstractentity { private static final long serialversionuid = -1982937254314630067l; /* params */ public static final string exists_payroll_excludedidpayroll_param = "idpayroll"; public static final string exists_payroll_idpayrolltype_param = "idpayrolltype"; public static final string exists_payroll_idemployment_param = "idemployment"; public static final string exists_payroll_year_param = "year"; public static final string exists_payroll_month_param = "month"; public static final string exists_payroll_idextrapay_param = "idextrapay"; /* queries */ public static final string exists_by_id_query_name = "exists_payroll_by_id"; public static final string exists_by_id_query = "select e.idpayroll payrollentity e e.idpayroll = :" + exists_by_id_query_param; public static final string find_payroll_query_name = "exists_payroll_by_conceptual_id"; public static final string find_payroll_query = "select e payrollentity e e.idpayroll != :" + exists_payroll_excludedidpayroll_param + " , e.employment.idemployment = :" + exists_payroll_idemployment_param + " , e.year = :" + exists_payroll_year_param + " , e.month = :" + exists_payroll_month_param + " , e.payrolltype.idpayrolltype = :" + exists_payroll_idpayrolltype_param; public static final string find_extrapay_query_name = "exists_extrapay_by_conceptual_id"; public static final string find_extrapay_query = "select e payrollentity e e.idpayroll != :" + exists_payroll_excludedidpayroll_param + " , e.employment.idemployment = :" + exists_payroll_idemployment_param + " , e.year = :" + exists_payroll_year_param + " , e.month = :" + exists_payroll_month_param + " , e.payrolltype.idpayrolltype = :" + exists_payroll_idpayrolltype_param + " , e.extrapay.idextrapay = :" + exists_payroll_idextrapay_param; public static final string find_payrolls_by_employment_query_name = "find_payrolls_by_employment"; public static final string find_payrolls_by_employment_query = "select e payrollentity e e.employment.idemployment = :" + exists_payroll_idemployment_param + " , e.year = :" + exists_payroll_year_param + " , e.month = :" + exists_payroll_month_param; /* table */ public static final string table_name = "ep_payroll"; /* columns */ public static final string id_payroll_column = "id_payroll"; public static final string version_column = "version"; public static final string id_employment_column = "id_employment"; public static final string id_payroll_type_column = "id_payroll_type"; public static final string year_column = "year"; public static final string month_column = "month"; public static final string calculation_datetime_column = "calculation_datetime"; public static final string payslip_generation_datetime_column = "payslip_generation_datetime"; public static final string id_extra_pay_column = "id_extra_pay"; public static final string discount_rate_calculated = "discount_rate_calculated"; public static final string discount_rate_solicited = "discount_rate_solicited"; public static final string discount_rate_applied = "discount_rate_applied"; private string idpayroll; private int version; private payrolltypeentity payrolltype; private employmententity employment; private int year; private int month; private datetime calculationdatetime; private datetime payslipgenerationdatetime; private list<payrollsalaryitementity> payrollsalaryitems; private extrapayentity extrapay; private float discountratecalculated; private float discountratesolicited; private float discountrateapplied; @column(name = calculation_datetime_column) @type(type = joda_date_time_jpa_converter) public datetime getcalculationdatetime() { return calculationdatetime; } @column(name = discount_rate_applied, columndefinition = "decimal(4,2)") public float getdiscountrateapplied() { return discountrateapplied; } @column(name = discount_rate_calculated, columndefinition = "decimal(4,2)") public float getdiscountratecalculated() { return discountratecalculated; } @column(name = discount_rate_solicited, columndefinition = "decimal(4,2)") public float getdiscountratesolicited() { return discountratesolicited; } @manytoone(targetentity = employmententity.class) @joincolumn(name = id_employment_column, referencedcolumnname = employmententity.id_employment_column) public employmententity getemployment() { return employment; } @manytoone(targetentity = extrapayentity.class) @joincolumn(name = id_extra_pay_column, referencedcolumnname = extrapayentity.id_extra_pay_column) public extrapayentity getextrapay() { return extrapay; } @column(name = id_payroll_column, nullable = false, updatable = false, length = 36) @id @generatedvalue(generator = uuid_generator_name) @genericgenerator(name = uuid_generator_name, strategy = uuid_generator_strategy) public string getidpayroll() { return idpayroll; } @column(name = month_column) public int getmonth() { return month; } @onetomany(mappedby = "payroll", cascade = cascadetype.all, orphanremoval = true) public list<payrollsalaryitementity> getpayrollsalaryitems() { return payrollsalaryitems; } @audited(targetauditmode = relationtargetauditmode.not_audited) @manytoone(targetentity = payrolltypeentity.class) @joincolumn(name = id_payroll_type_column, referencedcolumnname = payrolltypeentity.id_payroll_type_column) public payrolltypeentity getpayrolltype() { return payrolltype; } @column(name = payslip_generation_datetime_column) @type(type = joda_date_time_jpa_converter) public datetime getpayslipgenerationdatetime() { return payslipgenerationdatetime; } @version public int getversion() { return version; } @column(name = year_column) public int getyear() { return year; } public void setcalculationdatetime(datetime calculationdate) { this.calculationdatetime = calculationdate; } public void setdiscountrateapplied(float discountrateapplied) { this.discountrateapplied = discountrateapplied; } public void setdiscountratecalculated(float discountratecalculated) { this.discountratecalculated = discountratecalculated; } public void setdiscountratesolicited(float discountratesolicited) { this.discountratesolicited = discountratesolicited; } public void setemployment(employmententity employment) { this.employment = employment; } public void setextrapay(extrapayentity extrapay) { this.extrapay = extrapay; } public void setidpayroll(string idpayroll) { this.idpayroll = idpayroll; } public void setmonth(int month) { this.month = month; } public void setpayrollsalaryitems(list<payrollsalaryitementity> payrollsalaryitems) { this.payrollsalaryitems = payrollsalaryitems; } public void setpayrolltype(payrolltypeentity payrolltype) { this.payrolltype = payrolltype; } public void setpayslipgenerationdatetime(datetime payslipgenerationdatetime) { this.payslipgenerationdatetime = payslipgenerationdatetime; } public void setversion(int version) { this.version = version; } public void setyear(int year) { this.year = year; } }
this code use data envers:
public payrollentity findhistorical(string idpayroll, datetime date) { auditreader reader = auditreaderfactory.get(getentitymanager()); return reader.find(payrollentity.class, idpayroll, (int) reader.createquery() .forrevisionsofentity(payrollentity.class, false, true) .add(auditentity.revisionproperty("revtimestamp").lt(date.getmillis())) .addprojection(auditentity.revisionnumber().max()) .add(auditentity.id().eq(idpayroll)) .getsingleresult()); }
then try map data dto using dozer, , error:
caused by: javax.persistence.entitynotfoundexception: unable find es.gc.epsilon.core.domain.salaryitementity id 15 @ org.hibernate.ejb.ejb3configuration$ejb3entitynotfounddelegate.handleentitynotfound(ejb3configuration.java:157) [hibernate-entitymanager-4.2.14.sp1-redhat-1.jar:4.2.14.sp1-redhat-1] @ org.hibernate.proxy.abstractlazyinitializer.checktargetstate(abstractlazyinitializer.java:262) [hibernate-core-4.2.14.sp1-redhat-1.jar:4.2.14.sp1-redhat-1] @ org.hibernate.proxy.abstractlazyinitializer.initialize(abstractlazyinitializer.java:176) [hibernate-core-4.2.14.sp1-redhat-1.jar:4.2.14.sp1-redhat-1] @ org.hibernate.proxy.abstractlazyinitializer.getimplementation(abstractlazyinitializer.java:286) [hibernate-core-4.2.14.sp1-redhat-1.jar:4.2.14.sp1-redhat-1] @ org.hibernate.proxy.pojo.javassist.javassistlazyinitializer.invoke(javassistlazyinitializer.java:185) [hibernate-core-4.2.14.sp1-redhat-1.jar:4.2.14.sp1-redhat-1]
as said, seems it's because dozer access deleted item payrollsalaryitems collection list main entity.
so, question is. it's possible map data entity containint deleted items in collection dto? doing on right way?
pd: using hibernate version 4.2.21.final
thanks in advance.
what describe problem identified both hhh-8093 , hhh-8051, both of tentatively scheduled hibernate envers 6.0 release.
if these before 6.0 release, i'll try.
obviously doesn't solve immediate need on hibernate envers 4.2, way quite old , no longer maintained or patched.
Comments
Post a Comment