【问题标题】:coldfusion fw1 (hibernate) basic join between tables - "Path expected for join!"表之间的coldfusion fw1(休眠)基本连接-“连接的预期路径!”
【发布时间】:2012-02-08 03:47:11
【问题描述】:

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

我有 3 个对象: - 接触 - ContactCategory_Link - 联系人类别

组件的详细信息将在简短说明哪些有效和哪些无效之后。

基本上一个联系人可以有很多类别,一个类别也可以有很多联系人。 因为我需要为每个链接添加不同的参数(例如,我想为每个联系人排序(最终用户必须能够重新排序类别),以及我的系统所需的其他信息)。 我没有使用多对多关系,因为似乎无法添加那种附加信息。

所以这是完美运行的请求:

<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>

感谢您的帮助。

【问题讨论】:

    标签: hibernate orm join coldfusion fw1


    【解决方案1】:

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

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

    【讨论】:

    • 在您的帮助下我找到了解决方案!太感谢了!我不认为它会那样工作,我脑子里有太多 SQL 啊 ;) 这个请求解决了我所有的问题:
    猜你喜欢
    • 2011-04-24
    • 2020-05-02
    • 1970-01-01
    • 1970-01-01
    • 2014-06-12
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多