openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pinaki Poddar (JIRA)" <>
Subject [jira] Created: (OPENJPA-253) SQL Ordering does not honour unique constraints on non-primary column(s)
Date Thu, 07 Jun 2007 19:20:25 GMT
SQL Ordering does not honour unique constraints on non-primary column(s)

                 Key: OPENJPA-253
             Project: OpenJPA
          Issue Type: Bug
            Reporter: Pinaki Poddar

In a same transaction, when an existing instance x is removed and a new instance y is created
(in that order), during commit, OpenJPA SQL ordering issues INSERT SQL prior to DELETE (though
the object operations invoked remove() before persist()).  

If x and y had the same value for one or more non-primary but unique column(s), then INSERT
fails when it preceeds DELETE. 

Simple example:

// a simple onject with a unique non-primary column
public class PObject {
	private long id;
	private String name;


Simple Test:

	public void testSQLOrderViolatesUniqueConstraintOnDeleteInsert () {
               // create an entity p
		OpenJPAEntityManager em = getEM();
		PObject p = new PObject();
               // Find an existing entity p1, create another entity p2
               // set p2 name same as that of p1 (name is unique in database)
               // remove p1 and *then* insert p2
               // commit fails
		em = getEM();
		PObject p1 = em.find(PObject.class, p.getId());
		PObject p2 = new PObject();

The second transaction commit fails as INSERT SQL corresponding to em.persist(p2) is issued
prior to DELETE corresponding to em.remove(p1), because p1 and p2 have the same value for
'name' field which, in a database, is represented as a non-primary but unique column. 


This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message