Solved

Coldfusion orm oneToMany join query don't work

Posted on 2013-06-21
3
488 Views
Last Modified: 2013-11-19
I have 2 persistent entities : Product & ProductMaterial.

Product can't be sumarize like This :

<cfproperty name="id" type="numeric" fieldtype="id" ormtype="int" generator="native" setter="false" hint="the unique id of the product">
...
<cfproperty name="materials" type="array" fieldtype="one-to-many" hint="the materials of the product" cfc="ProductMaterial" singularname="material" fkcolumn="productId"    orderby="name"  cascade="all-delete-orphan">

Open in new window


And ProductMaterial is :

<cfproperty name="id" type="numeric" fieldtype="id" ormtype="int" generator="native" setter="false" hint="the unique id of the material">
<cfproperty name="name" type="string" fieldtype="column" ormtype="string" length="50" validate="string" validateparams="{minLength=1,maxLength=50}" hint="the name of the material">

Open in new window


I want to get the products according a selected material, for instance 'Wood'

I have tried, among other things similar, this :

<cfset variables.products = ormExecuteQuery("from Product p join p.materials m where m.name = 'wood' and isPack=true order by referenceId desc")>

Open in new window


But it returns me 0 records (there must be 433 records !).

Do u have an idea what's wrong ?

Thanks.
0
Comment
Question by:adam1h
  • 2
3 Comments
 
LVL 25

Expert Comment

by:James Rodgers
ID: 39271184
the join doesn't seem correct


from Product p join p.materials m where m.name

should either be
 from Product p, materials m
Where p.col=m.com and m.name =

or
from Product p
LEFT JOIN  Materials m
on p.col=m.col
WHERE m.name=
0
 

Accepted Solution

by:
adam1h earned 0 total points
ID: 39272117
Hi,

Thanks for this idea, but in fact in HQL, there is no need to specify the field for the join, hibernate know it as it is mapped.

The problem was my type of relationship who was oneToMany. I have changed it to ManyToMany, who is more meaningful.

Also, I have a boolean field (isPack) whose possible values are T or F.
In an entityLoad function, I use isPack=true without trouble, but in the ormExecuteQuery function, it fail : I need to write isPack='T'.

Thanks for the help.
0
 

Author Closing Comment

by:adam1h
ID: 39286393
I have receive no corect answer, I have found myself the solution (as described in the comment).
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now