Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Coldfusion orm oneToMany join query don't work

Posted on 2013-06-21
3
Medium Priority
?
532 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

916 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