<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<title>n42 Designs - Transfer</title>
<link>http://www.n42designs.com/blog/index.cfm</link>
<description>n42 Designs Blog</description>
<language>en-us</language>
<pubDate>Sun, 05 Sep 2010 04:49:14 -0400</pubDate>
<lastBuildDate>Tue, 17 Feb 2009 10:43:00 -0400</lastBuildDate>
<generator>BlogCFC</generator>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<managingEditor>sean@n42designs.com</managingEditor>
<webMaster>sean@n42designs.com</webMaster>
<itunes:subtitle></itunes:subtitle>
<itunes:summary></itunes:summary>
<itunes:category text="Technology" />
<itunes:category text="Technology">
<itunes:category text="Podcasting" />
</itunes:category>
<itunes:category text="Technology">
<itunes:category text="Tech News" />
</itunes:category>
<itunes:keywords></itunes:keywords>
<itunes:author></itunes:author>
<itunes:owner>
<itunes:email>sean@n42designs.com</itunes:email>
<itunes:name></itunes:name>
</itunes:owner>
<itunes:image href="" />
<image>
<url></url>
<title>n42 Designs</title>
<link>http://www.n42designs.com/blog/index.cfm</link>
</image>
<itunes:explicit>no</itunes:explicit>
<item>
<title>Transfer Error when using ntext
or text and a ManyToMany Relationship</title>
<link>http://www.n42designs.com/blog/index.cfm/2009/2/17/Transfer-Error-when-using-ntext-or-text-and-a-ManyToMany-Relationship</link>
<description>
When you set Transfer to use a
table that has an ntext or text column on SQL Server 2000 (and perhaps
later versions) and also a many to many relationship you may receive the
following error when you attempt to retreive the collection for the many
to many:
&lt;code&gt;[Macromedia][SQLServer JDBC Driver][SQLServer]Only
text pointers are
allowed in work tables, never text, ntext, or image
columns. The query
processor produced a query plan that required a
text, ntext, or image
column in a work table.&lt;/code&gt;
For
example I have the following tables set up
&lt;code&gt;Table Name:
Table1
id	char(35)	primary key
title
varchar(255)
description	ntext
Table Name: Table2
id
char(35)	primary key
description
varchar(255)
Table Name: Table1_Table2
table1_id	char(35)
composite key
table2_id	char(35)	composite
key&lt;/code&gt;
And the following transfer
configuration:
&lt;code&gt;&lt;transfer&gt;
&lt;objectDefinitions&gt;
&lt;object name=&quot;Table1&quot; table=&quot;table1&quot;&gt;
&lt;id
name=&quot;id&quot; type=&quot;UUID&quot; generate=&quot;true&quot; /&gt;
&lt;property name=&quot;title&quot; type=&quot;string&quot; nullable=&quot;false&quot; /&gt;
&lt;property name=&quot;description&quot; type=&quot;string&quot; nullable=&quot;true&quot; /&gt;
&lt;manytomany name=&quot;Relation&quot; table=&quot;Table1_Table2&quot; lazy=&quot;true&quot;&gt;
&lt;link to=&quot;Table1&quot; column=&quot;table1_id&quot; /&gt;
&lt;link to=&quot;Table2&quot; column=&quot;table2_id&quot; /&gt;
&lt;collection type=&quot;array&quot;&gt;
&lt;order
property=&quot;description&quot; order=&quot;asc&quot; /&gt;
&lt;/collection&gt;
&lt;/manytomany&gt;
&lt;/object&gt;
&lt;object name=&quot;Table2&quot; table=&quot;Table2&quot;&gt;
&lt;id name=&quot;id&quot; type=&quot;UUID&quot; generate=&quot;true&quot; /&gt;
&lt;property name=&quot;description&quot; type=&quot;string&quot; nullable=&quot;false&quot; /&gt;
&lt;/object&gt;
&lt;/objectDefinitions&gt;
&lt;/transfer&gt;&lt;/code&gt;
So
when you call getRelationArray() on a Table1 object. You will receive
the error. To correct this I took the following steps:
Create a
for table 1 with the ntext column casted to varchar:
select
id,title,cast(description as varchar(8000)) as description from
table1
Save this as vwTable1.
Change your transfer config
to point to the view instead of table one so
&lt;code&gt;&lt;object
name=&quot;Table1&quot; table=&quot;table1&quot;&gt;&lt;/code&gt;
becomes
&lt;code&gt;&lt;object
name=&quot;Table1&quot; table=&quot;vwTable1&quot;&gt;&lt;/code&gt;
Now, you wont be able to
run it yet because the view is not updatable since you used the casted
field. To overcome this we are going to use an INSTEAD OF
trigger.
You need to create 2 triggers. One will be called
whenever UPDATE is called on the vwTable1 and the other will be called
when INSERT INTO is called on vwTable1
You can create the
triggers as follows, obviously change it to suit your table&apos;s
needs:
&lt;code&gt;CREATE trigger io_trigger_insert_vwTable1 on
vwTable1
instead of insert
as
begin
set nocount
on
if (not exists (select t.[id] from table1 t, inserted i where
t.[id] = i.[id]))
insert into table1
select
[id],
[title],
[description]
from
inserted
end&lt;/code&gt;
&lt;code&gt;create
trigger io_trigger_update_vwAd on vwAd
instead of update
as
begin
set nocount on
if (exists (select t.[id] from table1 t,
inserted i where t.[id] = i.[id]))
update
table1
set
title = i.title,
[description] = i.[description]
from
table1
t, inserted i
where
t.[id] =
i.[id]
end&lt;/code&gt;
Once you have created these triggers you
should be able to use Transfer as you normally would. Using the casted
column in the view will allow you to call the getRelationArray(). The
SQL that Transfer creates will no longer be invalid.
You may run
into a couple of other items though. First, your ntext field is now
limited to 8000 characters since you are casting it to varchar. You may
be able to increase this, but I haven&apos;t tried. Your mileage may vary,
but be sure before the value is passed to transfer that it is validated
as less than 8000 characters (perhaps in your decorator). Next, if you
have any non-null, defaulted columns in your base table (a created date
perhaps) you HAVE to provide a value when you call insert into vwTable1.
Since Transfer is creating this SQL you have to ensure that Transfer
includes that column. This means that you cannot use the
ignore-insert=&quot;true&quot; option in the transfer configuration. SQL Server
will still respect your default value, as long as you provide that
column in the sql statement pointed at the view.
You can find
more information about &lt;a
href=&quot;http://msdn.microsoft.com/en-us/library/aa214478(SQL.80).aspx&quot;&gt;INSTEAD
OF INSERT&lt;/a&gt; and &lt;a
href=&quot;http://msdn.microsoft.com/en-us/library/aa214430(SQL.80).aspx&quot;&gt;INSTEAD
OF UPDATE&lt;/a&gt; triggers on the MSDN site.
I have only used this in
a simple application with two base tables and one relationship table, so
if your setup is more complex it may not work out for you.
</description>
<category>Transfer</category>
<category>ColdFusion</category>
<pubDate>Tue, 17 Feb 2009 10:43:00 -0400</pubDate>
<guid>http://www.n42designs.com/blog/index.cfm/2009/2/17/Transfer-Error-when-using-ntext-or-text-and-a-ManyToMany-Relationship</guid>
</item>
</channel></rss>