Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Datadeploy to associative table with foreign key constraints
relpek
I am having problems deploying from a single content record to a database schema with three tables, two data tables and one associative table. Referential integrity is being enforced in the DB with foreign key constraints, so I can only deploy data to table1, then table2, and finally to the AssociativeTable. Looks something like this:
Table1
ID
Name
AssociativeTable1
Table1ID
Table2ID
Table2
ID
Name
I can't figure out if it is possible to deploy to these tables without removing the constraints first. The way you set up a datadeploy config file forces you into a chain of parent, child, grandchild etc., so that datadeploy will always want to deploy to Table1, then the AssociativeTable, and finally Table2.
Sample DD config file is below. The only way I've been able to get this to work is to remove the table constraints, deploy, and add the constraints back. Is this possible?
-John
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<data-deploy-configuration>
<data-deploy-elements filepath="path/to/database.xml" />
<client>
<deployment name="testassoc">
<source>
<teamsite-templating-records custom="yes" options="wide" area="path/to/STAGING" include-extended-attributes="yes">
<path name="templatedata/path/to/data" />
</teamsite-templating-records>
</source>
<destinations>
<database use="DevDB" update-type="standalone" state-field="state" enforce-ri="yes">
<dbschema>
<!-- === Table: table_one === -->
<group name="table_one" table="table_one" root-group="yes">
<attrmap>
<column name="ID" data-type="INTEGER" value-from-element="page/0/ID/0" allows-null="no" />
<column name="Path" data-type="VARCHAR(256)" value-from-field="path" allows-null="no" />
<column name="Name" data-type="VARCHAR(256)" value-from-element="page/0/Name/0" allows-null="no" />
</attrmap>
<keys>
<primary-key>
<key-column name="ID" />
</primary-key>
</keys>
</group>
<!-- === Table: table_assoc === -->
<group name="table_assoc" table="table_assoc" root-group="no">
<attrmap>
<column name="TableOneID" data-type="INTEGER" value-from-field="page/0/ID/0" allows-null="no" />
<column name="TableTwoID" data-type="INTEGER" value-from-element="page/0/Group/0/ID/0" allows-null="no" />
</attrmap>
<keys>
<primary-key>
<key-column name="TableOneID" />
<key-column name="TableTwoID" />
</primary-key>
<foreign-key parent-group="table_one" ri-constraint-rule="ON DELETE CASCADE">
<column-pair parent-column="ID" child-column="TableOneID" />
</foreign-key>
</keys>
</group>
<!-- === Table: table_two === -->
<group name="table_two" table="table_two" root-group="no">
<attrmap>
<column name="ID" data-type="INTEGER" value-from-field="page/0/Group/0/ID/0" allows-null="no" />
<column name="Name" data-type="VARCHAR(256)" value-from-element="page/0/Group/0/Name/0" allows-null="no" />
</attrmap>
<keys>
<primary-key>
<key-column name="ID" />
</primary-key>
<foreign-key parent-group="table_assoc" ri-constraint-rule="ON DELETE CASCADE">
<column-pair parent-column="TableTwoID" child-column="ID" />
</foreign-key>
</keys>
</group>
</dbschema>
</database>
</destinations>
</deployment>
</client>
</data-deploy-configuration>
Find more posts tagged with
Comments
Adam Stoller
Have you tried changing the configuration file to define the associative table
last
instead of second?
relpek
Yep. Unfortunately it doesn't work. It looks like Datadeploy builds the order of the insert statements based on the parent child relationship first. I can only get it to wok by removing the foreign key relationship in the associative table in the dd config file, and then it will respect the order. So with the groups in the order you suggest but with foreign key relationships preserved, I get:
DBD: TTableSchemaHelper not found in cache for [table_one]. Creating new.
DBD: RowsExistForPath
ELECT COUNT(*) FROM table_one WHERE path = ?
DBD: INSERT:INSERT INTO table_one(ID,Path,Name) VALUES (?,?,?)
... snip ...
DBD: TTableSchemaHelper not found in cache for [table_assoc]. Creating new.
DBD: INSERT:INSERT INTO table_assoc(TableOneID,TableTwoID) VALUES (?,?)
DBD: Column: TableOneID, field: page/0/ID/0, Index: 1,Converting '378' to INTEGER
DBD: Column: TableTwoID, value-from-element: page/0/Group/0/ID/0, Index: 2,Converting '2219' to INTEGER
DBD:
DBD: *******************************************************
DBD: SQLException occured in TDbSchemaGroupCfg
DBD: Exception Message: [PHINSQL2D]INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_table_assoc_TableTwoID'. The conflict occurred in database 'Test2', table 'table_two', column 'ID'.
DBD: Vendor Error Code: 547
DBD: SQL state: 23000
DBD: *******************************************************
DBD:
DBD: *******STACK TRACE*************
DBD: ERROR:
java.sql.SQLException: [PHINSQL2D]INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_table_assoc_TableTwoID'. The conflict occurred in database 'Test2', table 'table_two', column 'ID'.
at com.inet.tds.e.a(Unknown Source)
at com.inet.tds.e.a(Unknown Source)
at com.inet.tds.b.new(Unknown Source)
at com.inet.tds.b.executeUpdate(Unknown Source)
at com.interwoven.dd100.dd.TDbSchemaGroupCfg.PerformInsertForColumnArray(TDbSchemaGroupCfg.java:1289)
at com.interwoven.dd100.dd.TDbSchemaGroupCfg.PerformInsert(TDbSchemaGroupCfg.java:1165)
at com.interwoven.dd100.dd.TDbSchemaGroupCfg.DoInsert(TDbSchemaGroupCfg.java:1077)
at com.interwoven.dd100.dd.TDbSchemaCfg.InsertWithGroupTree(TDbSchemaCfg.java:456)
at com.interwoven.dd100.dd.TDbSchemaCfg.Insert(TDbSchemaCfg.java:409)
at com.interwoven.dd100.dd.TDbSchemaAgent.BasicWriteTuple(TDbSchemaAgent.java:477)
at com.interwoven.dd100.dd.TDbSchemaAgent.WriteTuple(TDbSchemaAgent.java:336)
at com.interwoven.dd100.dd.TPredicateEvaluator.WriteTuple(TPredicateEvaluator.java:116)
at com.interwoven.dd100.dd.TTupleSubstitutor.WriteTuple(TTupleSubstitutor.java:113)
at com.interwoven.dd100.dd.TTupleSubstitutor.WriteTuple(TTupleSubstitutor.java:113)
at com.interwoven.dd100.dd.TConsumerManager.WriteConsumerInternal(TConsumerManager.java:399)
at com.interwoven.dd100.dd.TConsumerManager.WriteConsumers(TConsumerManager.java:388)
at com.interwoven.dd100.dd.TAgentClient.DoOneTeamSiteSource(TAgentClient.java:1008)
at com.interwoven.dd100.dd.TAgentClient.DoTeamSiteSources(TAgentClient.java:502)
at com.interwoven.dd100.dd.TAgentClient.DoOneDeployment(TAgentClient.java:289)
at com.interwoven.dd100.dd.TAgentClient.Go(TAgentClient.java:178)
at com.interwoven.dd100.dd.IWDataDeploy.Go(IWDataDeploy.java:582)
at com.interwoven.dd100.dd.IWDataDeploy.run(IWDataDeploy.java:608)
at java.lang.Thread.run(Thread.java:534)
DBD: ERROR
oInsert() failed for group [table_assoc].
DBD: -- Failed