Solved

Coldfusion orm oneToMany join query don't work

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Coldfusion Complex Structure Reference 4 37
How to get the web content with different encodings 2 48
Edit a page at wix.com 8 51
Shopping Cart 2 75
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
The viewer will learn how to dynamically set the form action using jQuery.

832 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