我试着做一个基本的连接,在SQL中需要几秒钟,但是.我试图让它与ORMExecuteQuery (基于Hibernate的Coldfusion9)一起工作。
我有三个对象:-联系人- ContactCategory_Link - ContactCategory
组件的详细信息将在简短地描述了什么在起作用和什么不起作用之后。
基本上,一个联系人可以有许多类别,一个类别也可以有许多联系人。因为我需要为每个链接添加不同的参数(例如,我想为每个联系人排序类别(最终用户必须能够重新排序),再加上我的系统所需要的其他信息)。我没有使用多对多的关系,因为似乎不可能添加这样的额外信息。
因此,以下是完美工作的请求:
<cfset response["rows"] = ORMExecuteQuery("
SELECT new map(c.name as Name)
FROM Contact c
")>它完美地给出了联系人的名字。但是,每次我尝试添加另一个表时,它都会失败。例如:
<cfset response["rows"] = ORMExecuteQuery("
SELECT new map(c.name as Name)
FROM Contact c
JOIN ContactCategory_Link
")>将给予:
Path expected for join! 即使我将ContactCategory_Link改为ContactCategory_Link.contact,它也会提供如下内容:
Invalid path: 'null.contact'因此,我猜我的组件CFC没有正确设置,但我不明白为什么。
你能帮我解决这个问题吗?
以下是每个对象的代码:
<cfcomponent displayname="Contact" entityname="Contact" table="step8_contact" persistent="true" output="false">
<cfproperty name="id" column="contactID" type="guid" fieldtype="id" setter="false" unique="true" notnull="true" generated="insert" generator="identity">
<cfproperty name="name" column="name" type="string" length="125" required="true">
<cfproperty name="categories" fieldtype="one-to-many" singularname="category" fkcolumn="contactID" cfc="ContactCategory_Link" missingRowIgnored="true" cascade="all-delete-orphan">
</cfcomponent><cfcomponent displayname="ContactCategory_Link" entityname="ContactCategory_Link" table="step8_contactcategory_link" persistent="true" output="false">
<cfproperty name="id" column="contactcategory_linkID" type="numeric" fieldtype="id" setter="false" unique="true" notnull="true" generated="insert" generator="identity">
<cfproperty name="orderId" column="orderId" type="numeric" required="true"> <!---notnull="true"--->
<cfproperty name="contact" fieldtype="many-to-one" fkcolumn="contactID" cfc="Contact" missingRowIgnored="true">
<cfproperty name="contactcategory" fieldtype="many-to-one" fkcolumn="contactcategoryID" cfc="ContactCategory" missingRowIgnored="true">
</cfcomponent><cfcomponent displayname="ContactCategory" output="false" persistent="true" entityname="ContactCategory" table="step8_contactcategories" hint="" cacheuse="read-only" cachename="contactcategory">
<cfproperty name="id" column="contactcategoryID" type="numeric" fieldtype="id" setter="false" unique="true" notnull="true" generated="insert" generator="identity">
<cfproperty name="label" column="label" type="string" length="255" required="true" notnull="true">
<cfproperty name="orderId" column="orderId" type="numeric" required="true" notnull="true">
<cfproperty name="categories" fieldtype="one-to-many" singularname="category" fkcolumn="contactcategoryID" cfc="ContactCategory_Link" missingRowIgnored="true" cascade="all-delete-orphan" lazy="true">
</cfcomponent>谢谢你的帮助。
发布于 2012-01-12 07:58:52
cfset可能是hql查询(hibernate查询语言=对象查询语言)。你需要
<cfset response["rows"] = ORMExecuteQuery("
SELECT c.name as Name, cat.whatever as Whatever
FROM Contact c
JOIN c.Categories cat
")>https://stackoverflow.com/questions/8825181
复制相似问题