Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0034657Openbravo ERPA. Platformpublic2016-11-30 16:492017-07-03 18:11
0034657: inconsistent behavior of OBDal.get when trying to get an inexistent record
When OBDal.get is used to get a record which ID does not exist in DB, it returns null.

Previous statement is true as far as there was not a proxy for the same object in Hibernate cache, in this case an ObjectNotFoundException is thrown.

1. BusinessPartner bpProxy = OBDal.getInstance().getProxy(BusinessPartner.class, "dummyId");
2. final BusinessPartner bpartner = OBDal.getInstance().get(BusinessPartner.class, "dummyId");

Then, the query breaks if the object does not exist in DB.

Workaround: If we use "OBDal.getInstance().getSession().evict(bpProxy);" sentence before make the query, it works succesfully
Add catch clause in OBDal class in get method:
public <T extends Object> T get(Class<T> clazz, Object id) {
    try {
      return SessionHandler.getInstance().find(clazz, id);
    } catch (org.hibernate.ObjectNotFoundException e) {
      return null;
No tags attached.
related to defect 0036391 closed alostale inconsistent behavior of OBDal.get by entity name + id when trying to populate a proxy by entity name + id 
diff OBDalPatch.diff (539) 2016-11-30 16:49
Issue History
2016-11-30 16:49kchoperenaNew Issue
2016-11-30 16:49kchoperenaAssigned To => alostale
2016-11-30 16:49kchoperenaFile Added: OBDalPatch.diff
2016-11-30 16:49kchoperenaModules => Core
2016-11-30 16:49kchoperenaTriggers an Emergency Pack => No
2016-11-30 17:39alostaleAssigned Toalostale => platform
2016-11-30 17:39alostaleStatusnew => acknowledged
2016-11-30 17:39alostaleCategoryY. DBSourceManager => A. Platform
2016-12-01 13:17alostalePrioritynormal => urgent
2016-12-01 14:14alostaleStatusacknowledged => scheduled
2016-12-01 14:14alostaleAssigned Toplatform => alostale
2016-12-01 16:06alostaleSummaryWhen we try to make a query of any object that not exist in DB but we have a proxy opened before, the query breaks => inconsistent behavior of OBDal.get when trying to get an inexistent record
2016-12-01 16:06alostaleDescription Updatedbug_revision_view_page.php?rev_id=13928#r13928
2016-12-01 16:06alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=13930#r13930
2016-12-01 16:06alostaleReview Assigned To => caristu
2016-12-01 16:11hgbotCheckin
2016-12-01 16:11hgbotNote Added: 0091980
2016-12-01 16:11hgbotStatusscheduled => resolved
2016-12-01 16:11hgbotResolutionopen => fixed
2016-12-01 16:11hgbotFixed in SCM revision => [^]
2016-12-02 15:40caristuNote Added: 0092044
2016-12-02 15:40caristuStatusresolved => closed
2016-12-02 15:40caristuFixed in Version => 3.0PR17Q1
2016-12-16 18:39hudsonbotCheckin
2016-12-16 18:39hudsonbotNote Added: 0092680
2017-07-03 18:11ngarciaIssue cloned0036391
2017-07-03 18:13ngarciaRelationship addedrelated to 0036391

2016-12-01 16:11   
Repository: erp/devel/pi
Changeset: 72cd92b69d6292e4933c46b43d916ffb900604fc
Author: Asier Lostalé <asier.lostale <at>>
Date: Thu Dec 01 16:10:42 2016 +0100
URL: [^]

fixed bug 34657: inconsistent behavior of OBDal.get

  OBDal.get behaved inconsistently when trying to obtain an object for an ID that
  is not present in DB:

   -It usually returns null
   -unless there was a proxy for the same object, which thrown an exception

  Fixed by making it to always return null in this case.

M src-test/src/org/openbravo/test/dal/
M src/org/openbravo/dal/service/
2016-12-02 15:40   
Code review + testing OK.
2016-12-16 18:39   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: [^]
Maturity status: Test