You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by "Bill Fan (JIRA)" <ji...@apache.org> on 2006/04/29 00:48:52 UTC

[JIRA] Created: (CAY-536) How to enforce Delete before Insert?

How to enforce Delete before Insert?
------------------------------------

         Key: CAY-536
         URL: http://issues.apache.org/cayenne/browse/CAY-536
     Project: Cayenne
        Type: Bug

  Components: Cayenne Core Library  
    Versions: 1.2 [BETA]    
 Environment: XPP, MSSQL 2005 Express (MSSQL 2000 should be fine I guess), Tomcat 5.0.28, Spring 1.2.7
    Reporter: Bill Fan


We have  Product & ProductRelation tables. When we need to add a new ProductRelation record to a product, we like to delete all the existing ProductRelation records first, then add the new one.

We are having the "Cannot insert duplicate key..." error. It appears that the DELETE statement is executed after the INSERT statement.

Here is the stripped down datamap:

	<db-entity name="Product" schema="dbo" catalog="iCon">
		<db-attribute name="ProductId" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
		<db-attribute name="ProductName" type="VARCHAR" isMandatory="true" length="100"/>
	</db-entity>
	<db-entity name="ProductRelation" schema="dbo" catalog="iCon">
		<db-attribute name="ProductId" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
		<db-attribute name="RelatedProductid" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
		<db-attribute name="TypeId" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
	</db-entity>
	<db-entity name="Type" schema="dbo" catalog="iCon">
		<db-attribute name="Description" type="VARCHAR" isMandatory="true" length="50"/>
		<db-attribute name="TypeId" type="INTEGER" isPrimaryKey="true" isMandatory="true" length="10"/>
	</db-entity>


	<obj-entity name="Product" className="fanscom.model.Product" lock-type="optimistic" dbEntityName="Product" superClassName="org.objectstyle.cayenne.CayenneDataObject">
		<obj-attribute name="productName" type="java.lang.String" db-attribute-path="ProductName"/>
	</obj-entity>
	<obj-entity name="ProductRelation" className="fanscom.model.ProductRelation" lock-type="optimistic" dbEntityName="ProductRelation" superClassName="org.objectstyle.cayenne.CayenneDataObject">
	</obj-entity>
	<obj-entity name="Type" className="fanscom.model.Type" lock-type="optimistic" dbEntityName="Type" superClassName="org.objectstyle.cayenne.CayenneDataObject">
		<obj-attribute name="description" type="java.lang.String" db-attribute-path="Description"/>
	</obj-entity>


	<db-relationship name="productRelationArray" source="Product" target="ProductRelation" toDependentPK="true" toMany="true">
		<db-attribute-pair source="ProductId" target="ProductId"/>
	</db-relationship>
	<db-relationship name="productRelationArray1" source="Product" target="ProductRelation" toDependentPK="true" toMany="true">
		<db-attribute-pair source="ProductId" target="RelatedProductid"/>
	</db-relationship>
	<db-relationship name="toProduct" source="ProductRelation" target="Product" toMany="false">
		<db-attribute-pair source="ProductId" target="ProductId"/>
	</db-relationship>
	<db-relationship name="toProduct1" source="ProductRelation" target="Product" toMany="false">
		<db-attribute-pair source="RelatedProductid" target="ProductId"/>
	</db-relationship>
	<db-relationship name="toType" source="ProductRelation" target="Type" toMany="false">
		<db-attribute-pair source="TypeId" target="TypeId"/>
	</db-relationship>



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/cayenne/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira