Bug 1370040 - [GSS] (6.4.z) DuplicateKeyException is not always thrown even if Constraint Violation happens at EJB 2 CMP creation
Summary: [GSS] (6.4.z) DuplicateKeyException is not always thrown even if Constraint V...
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: EJB
Version: 6.4.9
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: CR1
: EAP 6.4.12
Assignee: Fedor Gavrilov
QA Contact: Jan Martiska
URL:
Whiteboard: eap6412-proposed
Depends On:
Blocks: eap6412-payload
TreeView+ depends on / blocked
 
Reported: 2016-08-25 06:52 UTC by Masafumi Miura
Modified: 2019-11-14 08:59 UTC (History)
8 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2017-01-17 13:13:15 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
BZ1370040_proposed_patch.diff (1.21 KB, patch)
2016-08-25 06:53 UTC, Masafumi Miura
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 2572271 0 None None None 2016-11-16 09:18:22 UTC

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.


Note You need to log in before you can comment on or make changes to this bug.