Solved

Coldfusion orm oneToMany join query don't work

Posted on 2013-06-21
3
509 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Company website 6 44
asp Google Map 2 55
How to remove a section of the main menu from Magento 1.9.3 3 20
SP result not being displayed 5 35
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

680 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