首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >coldfusion fw1 (hibernate)表之间的基本连接--“期望加入的路径!”

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

Stack Overflow用户
提问于 2012-01-11 19:07:44
回答 1查看 2K关注 0票数 2

我试着做一个基本的连接,在SQL中需要几秒钟,但是.我试图让它与ORMExecuteQuery (基于Hibernate的Coldfusion9)一起工作。

我有三个对象:-联系人- ContactCategory_Link - ContactCategory

组件的详细信息将在简短地描述了什么在起作用和什么不起作用之后。

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

因此,以下是完美工作的请求:

代码语言:javascript
复制
<cfset response["rows"] = ORMExecuteQuery("
        SELECT new map(c.name as Name)
        FROM Contact c
        ")>

它完美地给出了联系人的名字。但是,每次我尝试添加另一个表时,它都会失败。例如:

代码语言:javascript
复制
<cfset response["rows"] = ORMExecuteQuery("
        SELECT new map(c.name as Name)
        FROM Contact c
        JOIN ContactCategory_Link
        ")>

将给予:

代码语言:javascript
复制
Path expected for join! 

即使我将ContactCategory_Link改为ContactCategory_Link.contact,它也会提供如下内容:

代码语言:javascript
复制
Invalid path: 'null.contact'

因此,我猜我的组件CFC没有正确设置,但我不明白为什么。

你能帮我解决这个问题吗?

以下是每个对象的代码:

代码语言:javascript
复制
<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>

代码语言:javascript
复制
<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>

代码语言:javascript
复制
<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>

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-12 07:58:52

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

代码语言:javascript
复制
<cfset response["rows"] = ORMExecuteQuery("
    SELECT c.name as Name, cat.whatever as Whatever
    FROM Contact c
    JOIN c.Categories cat
    ")>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8825181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档