Bug 1370040

Summary: [GSS] (6.4.z) DuplicateKeyException is not always thrown even if Constraint Violation happens at EJB 2 CMP creation
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Masafumi Miura <mmiura>
Component: EJBAssignee: Fedor Gavrilov <fgavrilo>
Status: CLOSED CURRENTRELEASE QA Contact: Jan Martiska <jmartisk>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.4.9CC: bmaxwell, david.lloyd, fgavrilo, jbilek, jtruhlar, ppalaga, psotirop, tanabe.yoshimasa
Target Milestone: CR1   
Target Release: EAP 6.4.12   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: eap6412-proposed
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-01-17 13:13:15 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On:    
Bug Blocks: 1375585    
Attachments:
Description Flags
BZ1370040_proposed_patch.diff none

Description Masafumi Miura 2016-08-25 06:52:06 UTC
DuplicateKeyException is not thrown even if Constraint Violation happens at EJB 2 CMP creation.

EJB 2 CMP does not throw DuplicateKeyException for some database even if Constraint Violation happens.

When <entity-command name="no-select-before-insert "/> is set in jbosscmp-jdbc.xml, 
SQLExceptionProcessor.isDuplicateKey(e) is called to detect constraint violation at EJB 2 CMP Creation org.jboss.as.cmp.jdbc.JDBCAbstractCreateCommand#performInsert() .

However, SQLExceptionProcessor.isDuplicateKey(e) check only if SQLState is equal to "23000". And some database does not alway returns 23000 as SQLState for constraint violation. For example, PostgreSQL may return 23505. Hence, DuplicateKeyException is not always thrown correctly.

As per SQL Standard convensions, SQLState values consist of 5 characters where the first two denotes a class and Class Code for Constraint Violation is "23". 

So, SQLExceptionProcessor.isDuplicateKey(e) should check if SQLState starts with "23" instead of checking if SQLState is equal to "23000".

Comment 1 Masafumi Miura 2016-08-25 06:53:14 UTC
Created attachment 1193888 [details]
BZ1370040_proposed_patch.diff

Comment 3 Jiří Bílek 2016-11-28 09:12:52 UTC
Verified with EAP 6.4.12.CP.CR1

Comment 4 Petr Penicka 2017-01-17 13:13:15 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.