Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0029258Openbravo ERP09. Financial managementpublic2015-03-12 13:512016-06-24 22:11
alostale 
Sandrahuguet 
normalmajorsometimes
closedfixed 
5
 
 
eduardo_Argal
Core
No
0029258: FIN_Utility.getDocumentNo method can return duplicates
FIN_Utility.getDocumentNo method can return duplicates.

It is the same problem reported in 0025075. This fix [1] seems to have two problems:

1. It tries to acquire a lock in ad_sequence only in case docType.getDocumentSequence() is null. If it is not null, no lock is acquired being possible to get duplicates.
2. The lock when docType.getDocumentSequence() is null seems not to be done in database. Testing it it PG a select statement without "for update" clause is sent to DB. This, most probably, occurs due to a hibernate issue [2]

[1] https://code.openbravo.com/erp/devel/pi/rev/e884b5f2318b77d3cbd8765541d5a5b4b5ebbef2 [^]
[2] https://hibernate.atlassian.net/browse/HHH-5275 [^]
It is hard to reproduce in a real environment as concurrency in very specific conditions is required:
-Thread A starts transaction
-Thread A gets document number for a concrete document type
-Thread B starts transaction
-Thread B gets document number for the same document type A got it
  --> B got the same number than A

Attached DocumentNumberGeneration class with test cases emulating these conditions. It fails for the cases:
-twoDalCalls
-dalFirstThenPL
-plFirstThenDal

-Is it required to have different implementations one in PL and another one in DAL?
-If both are required fix DAL:
  * Change current lock to prevent hibernate issue
  * Add lock for second case which currently is unattended

Attached export with proposed solution, pending to review with functional team.
No tags attached.
related to defect 0025075 closed eduardo_Argal FIN_Utility.getDocumentNo method can return the same documentno to same document and organization. 
? DocumentNumberGeneration.java (6,895) 2015-03-12 13:52
https://issues.openbravo.com/file_download.php?file_id=7887&type=bug
? issue-29258.export (15,390) 2015-03-12 15:20
https://issues.openbravo.com/file_download.php?file_id=7888&type=bug
Issue History
2015-03-12 13:51alostaleNew Issue
2015-03-12 13:51alostaleAssigned To => Sandrahuguet
2015-03-12 13:51alostaleModules => Core
2015-03-12 13:51alostaleTriggers an Emergency Pack => No
2015-03-12 13:52alostaleFile Added: DocumentNumberGeneration.java
2015-03-12 13:57alostaleSteps to Reproduce Updatedbug_revision_view_page.php?rev_id=7942#r7942
2015-03-12 13:58alostaleRelationship addedrelated to 0025075
2015-03-12 14:00alostaleProposed Solution updated
2015-03-12 15:19alostaleProposed Solution updated
2015-03-12 15:20alostaleFile Added: issue-29258.export
2016-01-19 05:00yogaskarnikIssue Monitored: yogaskarnik
2016-06-24 13:10hgbotCheckin
2016-06-24 13:10hgbotNote Added: 0087895
2016-06-24 13:10hgbotStatusnew => resolved
2016-06-24 13:10hgbotResolutionopen => fixed
2016-06-24 13:10hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/1c18bcb8922b1ed9cee90c9867ab5d9dfdb10358 [^]
2016-06-24 13:12eduardo_ArgalReview Assigned To => eduardo_Argal
2016-06-24 13:12eduardo_ArgalNote Added: 0087896
2016-06-24 13:12eduardo_ArgalStatusresolved => closed
2016-06-24 22:11hudsonbotCheckin
2016-06-24 22:11hudsonbotNote Added: 0087913

Notes
(0087895)
hgbot   
2016-06-24 13:10   
Repository: erp/devel/pi
Changeset: 1c18bcb8922b1ed9cee90c9867ab5d9dfdb10358
Author: David Miguelez <david.miguelez <at> openbravo.com>
Date: Fri Jun 24 13:09:36 2016 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/1c18bcb8922b1ed9cee90c9867ab5d9dfdb10358 [^]

Fixes Issue 29258. Fixes problem when locking a sequence number
to avoid duplicates. Now it locks the sequence number using
LockOptions.UPGRADE instead.

---
M modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/utility/FIN_Utility.java
A src-test/src/org/openbravo/advpaymentmngt/test/DocumentNumberGeneration.java
---
(0087896)
eduardo_Argal   
2016-06-24 13:12   
Reviewed and tested
(0087913)
hudsonbot   
2016-06-24 22:11   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/cc0900cf80c9 [^]
Maturity status: Test