Copy link to clipboard
Copied
Hey everyone.
Running CF 9.0.1 on Win7. I'm trying to get CF ORM to work, doing pretty well so far. I have a problem that I am hoping is not a showstopper.
My client has an MSSQL database and one of the tables in their OO structure is named "component", and has a many-to-many relationship with two other tables. When I try to define the relationship between this other table and "component":
<cfproperty name="components" type="array" fieldtype="many-to-many" cfc="component" linktable="xref" fkcolumn="other_table" inversejoincolumn="component" />
This is throwing an error:
CFC component could not be initialized. | |
Check if the persistent attribute in component is set to "true". | |
ColdFusion cannot determine the line of the template that caused this error. This is often caused by an error in the exception handling subsystem. |
When I comment out this cfproperty line, all the links work fine (except the one that the statement defines). I'm thinking that "component" is a reserved word in this context. The problem is, that is what the table and linktable fields are named, and I can't change it.
My question is: Am I screwed, or is there some sort of workaround I can do here?
Copy link to clipboard
Copied
Almost certainly it's reserved, and almost certainly there's no CF-based workaround.
The only thing I can think is to create a view, which is simply a "select * from components" but with a different name, then work from that.
Copy link to clipboard
Copied
MSSQL accepts named enclosed within square brackets, so you might try that. Ex. [component]
Copy link to clipboard
Copied
Thank you both for your responses.
Owen: I have a hard time believing that the folks who created CF ORM didn't think about how to allow users to use reserved words. That sucks.
EditCorp: I actually did. It is Hibernate that is throwing the exception, not SQL. Good suggestion tho.
Copy link to clipboard
Copied
mw_scitent wrote:
I have a hard time believing that the folks who created CF ORM didn't think about how to allow users to use reserved words.
Why so? Every language has words you can't use, that's what makes them reserved
Copy link to clipboard
Copied
Lulz. Two phrases: "Escape characters" and "Regular Expressions"
Copy link to clipboard
Copied
I'm thinking that "component" is a reserved word in this context.
Whatever it is, it's not that. I was able to create a component
Component.cfc, and create a one-to-many property in a
ComponentCollection.cfc which created.... well... a collection of Component
objects. Works fine.
CF's reporting of errors with the Hibernate subsystem is pretty rubbish, so
the errors you get can be misleading.
It'd be helpful if you posted a coupla CFCs and some calling code which
demonstrate your problem.
--
Adam
Copy link to clipboard
Copied
<!---- section.cfc - Section object, contains 1 to n Components ---->
<cfcomponent persistent="true" table="section" schema="dbo" output="false">
<cfproperty name="id" column="id" type="numeric" ormtype="int" fieldtype="id" />
Copy link to clipboard
Copied
Oh, and of course:
<cfset getSection = EntityLoad('Section',4, true)>
<cfdump var="#getSection#">
Copy link to clipboard
Copied
Cheers.
I don't have CF9 where I am currently, and won't be in front of a computer again until Sunday, but will try to look @ it then.
--
Adam
Copy link to clipboard
Copied
Thanks Adam. I am eager to hear what you experience is!
Copy link to clipboard
Copied
I was able to work around it today by defining the table name in a CFC that is not named the same as the table.
<!--- OtherComponent.cfc --->
<cfcomponent table="component" ...>
...
</cfcomponent>
<!--- Section.cfc --->
....
<cfproperty name="components" type="array" fieldtype="many-to-many" cfc="page" linktable="sectionxref" fkcolumn="section" inversejoincolumn="component" >
Thank you to those of you who tried to help with this problem! It is appreciated!