coldfusion fw1(hibernate)表之间的基本连接 - “期望加入的路径!”

时间:2012-01-11 19:07:45

标签: hibernate orm join coldfusion fw1

我正在尝试进行基本连接,这需要几秒钟的SQL但是...我正在尝试使用ORMExecuteQuery(基于Hibernate的Coldfusion 9)。

我有3个对象: - 联系 - 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>

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

cfset可能是一个hql-query(hibernate查询语言=对象查询语言)。你需要

<cfset response["rows"] = ORMExecuteQuery("
    SELECT c.name as Name, cat.whatever as Whatever
    FROM Contact c
    JOIN c.Categories cat
    ")>