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".
Created attachment 1193888 [details] BZ1370040_proposed_patch.diff
Verified with EAP 6.4.12.CP.CR1
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.