After a while working with iDempiere 2.0 , i found a critical problem with database transaction handling. The problem may result from my code, or from default transaction handling, or from the combination of both. I actually learnt quite a lot of database transactions handling between iDempiere and Postgres from it. (Assuming i'm using Postgresql 9.3)
But these are the cases that really bother me and make me think of a potential bug, plz correct me if my conclusion is mistaken.
Let take C_BPartner as an example:
- We got an Index in this table on database : UNIQUE INDEX c_bpartner_value to make sure the combination of AD_Client_ID and Value in this table is unique.
- We also define this index on iDempiere's Table & Column Configuration.
Steps to reproduce on iDempiere:
1. Create a Business Partner with Value = 'AAA'
2. Create another one with the same value and we got the error message on client which was defined on Table & Column:
"
Could not save record - Require unique data: - Please change information.: ERROR: duplicate key value violates unique constraint "c_bpartner_value" Detail: Key (ad_client_id, value)=(1000005, 000000) already exists."
3. In iDempiere Log :
"10:51:35.620===========> DB.saveError: SaveErrorNotUnique - ERROR: duplicate key value violates unique constraint "c_bpartner_value"
Detail: Key (ad_client_id, value)=(1000005, 000000) already exists. [41]
10:51:35.621-----------> MBPartner.doInsert: [POSaveC_BPartner_3012ace9-641d-44e1-b524-6ec182730cd0]Not inserted - C_BPartner [41]
10:51:35.635===========> MBPartner.saveError: SaveErrorNotUnique - ERROR: duplicate key value violates unique constraint "c_bpartner_value"
Detail: Key (ad_client_id, value)=(1000005, 000000) already exists. [41]
10:51:35.636-----------> GridTable.saveWarning: SaveErrorNotUnique - ERROR: duplicate key value violates unique constraint "c_bpartner_value"
Detail: Key (ad_client_id, value)=(1000005, 000000) already exists. [41]"
It's true that iDempiere already caught a situation where user tried to input another record into the database that violated unique constraint as expected.
But it doesn't stop there, looking into pg_log in Postgresql data folder, i found these lines:
"2015-03-27 10:51:35 ICT ERROR: duplicate key value violates unique constraint "c_bpartner_value"
2015-03-27 10:51:35 ICT DETAIL: Key (ad_client_id, value)=(1000005, 000000) already exists.
2015-03-27 10:51:35 ICT STATEMENT: INSERT INTO C_BPartner (IsCustomer,C_BPartner_UU,FlatDiscount,IsOneTime,SendEMail,SOCreditStatus,AcqusitionCost,IsSummary,IsDiscountPrinted,IsProspect,SalesVolume,DocumentCopies,ActualLifeTimeValue,ShareOfCustomer,IsEmployee,NumberEmployees,SO_CreditUsed,C_BPartner_ID,IsTaxExempt,IsPOTaxExempt,ShelfLifeMinPct,SO_CreditLimit,IsSalesRep,IsManufacturer,IsVendor,PotentialLifeTimeValue,TotalOpenBalance,CreatedBy,UpdatedBy,IsActive,Name,Value,Is1099Vendor,AD_Language,AD_Client_ID,AD_Org_ID,SalesRep_ID,C_BP_Group_ID,C_PaymentTerm_ID,M_PriceList_ID,Created,Updated) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42)
2015-03-27 10:51:35 ICT ERROR: current transaction is aborted, commands ignored until end of transaction block
2015-03-27 10:51:35 ICT STATEMENT: SELECT Version FROM AD_System"
Here is where i find it potentially critical bug since i've run into server hangs quite sometimes when database connections exceeded limitation due to unclosed connections.
For example when pg_log says:
"2015-03-26 10:40:00 ICT LOG: could not receive data from client: No connection could be made because the target machine actively refused it."
So, i'm desperately asking for help to fully understand this kind of situations when such problem thrown from database : current transaction is aborted, commands ignored until end of transaction block
Will it leave the connection just hang there without closing it or it's just normal ?
If it doesn't rollback transaction and close the connections, is this kind of problem related with the other problem i mention above -( database connections exceeded limitation)?
Looking forwards to learning from community's deep knowledge.
Best Regards