Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0029947Openbravo ERPA. Platformpublic2015-05-20 17:562022-02-01 08:07
jorge-garcia 
Triage Platform Base 
urgentmajoralways
acknowledgedopen 
5
 
 
Core
No
0029947: Wrong query launched when OBDal.getInstance.getSession.refresh(Object)
Wrong query launched when OBDal.getInstance.getSession.refresh(Object o) is executed
Warehouse w = OBDal.getInstance().get(Warehouse.class, "B2D40D8A5D644DD89E329DC297309055");
System.out.println(w);
OBDal.getInstance().getSession().refresh(w);

* Refresh query must be the same as Get query.

Get Query:
select warehouse0_.M_Warehouse_ID as M1_653_1_, warehouse0_.AD_Client_ID as AD2_653_1_,
    warehouse0_.AD_Org_ID as AD3_653_1_, warehouse0_.IsActive as IsActive653_1_,
    warehouse0_.Created as Created653_1_, warehouse0_.CreatedBy as CreatedBy653_1_,
    warehouse0_.Updated as Updated653_1_, warehouse0_.UpdatedBy as UpdatedBy653_1_,
    warehouse0_.Value as Value653_1_, warehouse0_.Name as Name653_1_,
    warehouse0_.Description as Descrip11_653_1_, warehouse0_.C_Location_ID as C12_653_1_,
    warehouse0_.Separator as Separator653_1_, warehouse0_.IsShipper as IsShipper653_1_,
    warehouse0_.Shippercode as Shipper15_653_1_, warehouse0_.FromDocumentNo as FromDoc16_653_1_,
    warehouse0_.ToDocumentNo as ToDocum17_653_1_, warehouse0_.M_Returnlocator_ID as M18_653_1_,
    warehouse0_.M_Warehouse_Rule_ID as M19_653_1_, warehouse0_.Isallocated as Isalloc20_653_1_
from M_Warehouse warehouse0_
where warehouse0_.M_Warehouse_ID=?

Refresh Query:
select warehouse0_.M_Warehouse_ID as M1_653_1_, warehouse0_.AD_Client_ID as AD2_653_1_,
    warehouse0_.AD_Org_ID as AD3_653_1_, warehouse0_.IsActive as IsActive653_1_,
    warehouse0_.Created as Created653_1_, warehouse0_.CreatedBy as CreatedBy653_1_,
    warehouse0_.Updated as Updated653_1_, warehouse0_.UpdatedBy as UpdatedBy653_1_,
    warehouse0_.Value as Value653_1_, warehouse0_.Name as Name653_1_,
    warehouse0_.Description as Descrip11_653_1_, warehouse0_.C_Location_ID as C12_653_1_,
    warehouse0_.Separator as Separator653_1_, warehouse0_.IsShipper as IsShipper653_1_,
    warehouse0_.Shippercode as Shipper15_653_1_, warehouse0_.FromDocumentNo as FromDoc16_653_1_,
    warehouse0_.ToDocumentNo as ToDocum17_653_1_, warehouse0_.M_Returnlocator_ID as M18_653_1_,
    warehouse0_.M_Warehouse_Rule_ID as M19_653_1_, warehouse0_.Isallocated as Isalloc20_653_1_,
    locatorlis1_.M_Warehouse_ID as M10_653_3_, locatorlis1_.M_Locator_ID as M1_3_,
    locatorlis1_.M_Locator_ID as M1_359_0_, locatorlis1_.AD_Client_ID as AD2_359_0_,
    locatorlis1_.AD_Org_ID as AD3_359_0_, locatorlis1_.IsActive as IsActive359_0_,
    locatorlis1_.Created as Created359_0_, locatorlis1_.CreatedBy as CreatedBy359_0_,
    locatorlis1_.Updated as Updated359_0_, locatorlis1_.UpdatedBy as UpdatedBy359_0_,
    locatorlis1_.Value as Value359_0_, locatorlis1_.M_Warehouse_ID as M10_359_0_,
    locatorlis1_.PriorityNo as PriorityNo359_0_, locatorlis1_.IsDefault as IsDefault359_0_,
    locatorlis1_.X as X359_0_, locatorlis1_.Y as Y359_0_,
    locatorlis1_.Z as Z359_0_, locatorlis1_.Barcode as Barcode359_0_,
    locatorlis1_.EM_OBWHS_Type as EM17_359_0_
from M_Warehouse warehouse0_
 left outer join M_Locator locatorlis1_ on warehouse0_.M_Warehouse_ID=locatorlis1_.M_Warehouse_ID
where warehouse0_.M_Warehouse_ID=?
Performance
related to defect 00252783.0PR15Q3 closed jorge-garcia Openbravo ERP Long time to update a warehouse if it has thousends of locators 
depends on defect 0030083 new Triage Omni OMS Openbravo ERP TestCosting fails adding one-to-many relationship to M_LandedCost 
related to defect 00303083.0PR15Q4 closed caristu Openbravo ERP Use get instead of refresh when saving or updating a record 
related to feature request 0037064 closed caristu Openbravo ERP upgrade hibernate to 5.3.2 
related to defect 0040157 closed AtulOpenbravo Modules Cannot reactivate a remittance: deleted object would be re-saved by cascade (remove deleted object from associations) 
related to feature request 0040290 closed alostale Openbravo ERP do not generate one-to-many property in parent entity for all FK properties 
Not all the children of this issue are yet resolved or closed.
diff 29947-proposal.diff (586) 2015-06-03 16:25
https://issues.openbravo.com/file_download.php?file_id=8164&type=bug
Issue History
2015-05-20 17:56jorge-garciaNew Issue
2015-05-20 17:56jorge-garciaAssigned To => platform
2015-05-20 17:56jorge-garciaModules => Core
2015-05-20 17:56jorge-garciaTriggers an Emergency Pack => No
2015-05-20 17:56jorge-garciaRelationship addedrelated to 0025278
2015-05-21 11:02alostalePriorityhigh => urgent
2015-05-21 11:02alostaleStatusnew => acknowledged
2015-05-21 11:02alostaleTarget Version => 3.0PR15Q3
2015-05-21 11:05alostaleTag Attached: Performance
2015-05-21 11:09jorge-garciaSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=8605#r8605
2015-05-28 14:17alostaleNote Added: 0077869
2015-06-03 16:25alostaleFile Added: 29947-proposal.diff
2015-06-03 16:26alostaleNote Added: 0078028
2015-06-03 16:30alostaleRelationship addeddepends on 0030083
2015-06-15 09:59alostaleTarget Version3.0PR15Q3 =>
2015-06-15 13:57jorge-garciaResolution time => 1436047200
2015-07-03 10:23caristuRelationship addedrelated to 0030308
2015-07-03 10:23caristuResolution time1436047200 =>
2015-11-06 11:05alostaleTypedefect => design defect
2018-07-25 09:19alostaleRelationship addedrelated to 0037064
2018-07-27 15:55alostaleNote Added: 0105993
2018-07-30 11:11alostaleNote Added: 0105998
2019-02-11 11:23caristuRelationship addedrelated to 0040157
2019-02-28 12:02alostaleNote Edited: 0077869bug_revision_view_page.php?bugnote_id=0077869#r18369
2019-02-28 12:51alostaleRelationship addedrelated to 0040290
2021-08-27 11:05cbernerNote Added: 0131396
2021-10-18 14:47cbernerNote Edited: 0131396bug_revision_view_page.php?bugnote_id=0131396#r23198
2022-02-01 08:07alostaleAssigned Toplatform => Triage Platform Base

Notes
(0077869)
alostale   
2015-05-28 14:17   
(edited on: 2019-02-28 12:02)
Hibernate refreshes parent and 1st (only 1st) child (bag) that is marked as Link to Parent (isParent) because of cascade="all,delete-orphan" in generated mapping.

org.hibernate.persister.entity.AbstractEntityPersister.createLoaders()
  ...
  loaders.put(
        "refresh",
        new CascadeEntityLoader( this, CascadingAction.MERGE, getFactory() )

org.hibernate.loader.entity.CascadeEntityLoader
...
    JoinWalker walker = new CascadeEntityJoinWalker(
        persister,
        action,
        factory);


org.hibernate.loader.JoinWalker.walkEntityTree(OuterJoinLoadable, String, PropertyPath, int)
      if ( type.isAssociationType() ) {
        walkEntityAssociationTree(

org.hibernate.loader.JoinWalker.walkEntityAssociationTree(AssociationType, OuterJoinLoadable, int, String, PropertyPath, boolean, int)

int joinType = getJoinType(
        persister,
        subPath,
        propertyNumber,
        associationType,
        persister.getFetchMode( propertyNumber ),
        persister.getCascadeStyle( propertyNumber ),
        lhsTable,
        lhsColumns,
        nullable,
        currentDepth
    ); -> 1 (includes it)


org.hibernate.loader.JoinWalker.getJoinType(AssociationType, FetchMode, PropertyPath, String, String[], boolean, int, CascadeStyle)

cascadeStyle -> [STYLE_ALL,STYLE_DELETE_ORPHAN]
isJoinedFetchEnabled -> true

it only adds 1st collection
  protected boolean isTooManyCollections() {
    return countCollectionPersisters(associations)>0;
  }

(0078028)
alostale   
2015-06-03 16:26   
attached proposed fix
(0105993)
alostale   
2018-07-27 15:55   
It is still reproducible in Hibernate 5.3.2.

Asked in Hibernate forums [1].

[1] https://discourse.hibernate.org/t/onetomany-get-initialized-on-refresh/1127 [^]
(0105998)
alostale   
2018-07-30 11:11   
Reported in Hibernate issue tracker:

https://hibernate.atlassian.net/browse/HHH-12867 [^]
(0131396)
cberner   
2021-08-27 11:05   
(edited on: 2021-10-18 14:47)
This issue is still not fixed on hibernate by https://issues.openbravo.com/view.php?id=45968 [^]

Hibernate issue https://hibernate.atlassian.net/browse/HHH-12867 [^] still reproducible in Hibernate 5.5.6 as still open.