Question

I'm trying to do a basic join which would take a few seconds in SQL but... I'm trying to get it working with ORMExecuteQuery (Coldfusion 9 based on Hibernate).

I have 3 objects: - Contact - ContactCategory_Link - ContactCategory

Components details will follow after the short description of what's working and what's not working.

Basically a contact can have many categories, and a category can have many contacts as well. Since I need to add different parameters for every link (for example I'd like to order the categories for each contact (end-users have to be able to reorder the categories), plus other information required by my system). I didn't use the many-to-many relationship because it does not seem to be possible to add that kind of additional information.

So here is the request that works perfectly:

<cfset response["rows"] = ORMExecuteQuery("
        SELECT new map(c.name as Name)
        FROM Contact c
        ")>

It gives perfectly the contact name. However each time I try to add another table, it will fail. For example:

<cfset response["rows"] = ORMExecuteQuery("
        SELECT new map(c.name as Name)
        FROM Contact c
        JOIN ContactCategory_Link
        ")>

Will give:

Path expected for join! 

Even if I'm changing ContactCategory_Link for ContactCategory_Link.contact, it will give something like:

Invalid path: 'null.contact'

So I'm guessing my components CFC are not set correctly, but I don't see why.

Could you help me on this subject?


Here's the code of each object:

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

Thanks for your help.

Was it helpful?

Solution

cfset is probably a hql-query (hibernate query language = object query language). you need to

<cfset response["rows"] = ORMExecuteQuery("
    SELECT c.name as Name, cat.whatever as Whatever
    FROM Contact c
    JOIN c.Categories cat
    ")>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top