entityLoad using filter criteria on a related entity

58 views
Skip to first unread message

Gregory Thrush

unread,
Aug 15, 2016, 8:16:11 PM8/15/16
to cf-orm-dev
Hello,

Logs is a data object with a few related entities

component persistent="true" accessors="true" table="logs" {

property name="id" fieldtype="id" ormtype="string" generator="assigned" length="16";

property name="directServices" type="array" singularname="directService" fieldtype="one-to-many" cfc="directServices" fkcolumn="fk_log_id" cascade="all" remotingFetch = true;

property name="referrals" type="array" singularname="referral" fieldtype="one-to-many" cfc="referrals" fkcolumn="fk_log_id" cascade="all"

property name="participants" type="array" singularname="participant" fieldtype="one-to-many" cfc="participants" fkcolumn="fk_log_id" cascade="all" remotingFetch = true;

}

The particpant entity attaches an array of participants to any given log.


component persistent="true" accessors="true" table="participants" {
property name="id" fieldtype="id" generator="native";
property name='logId' ormtype='string' length="16";
property name='participantId' ormtype='string' length="16";
}


1. Logs = EntityLoad( "logs")

successfully returns all of the log entities in the database as I would expect.

2. Logs = EntityLoad('participants', { participantID = rc.id})

successfully returns just the participants entity data without the associated log entity data. This makes sense and shows me that my filter criteria is working.

3. I want to return log entities containing the full data associated with a particular participant. When I try this:

Logs = EntityLoad( "logs", { participantID = rc.id } )

Hibernate throws the error: Property PARTICIPANTID not present in the entity. I'm not sure why Hibernate can't find participantID. My reading of the documentation indicates that Hibernate should be able to do this. What is the proper syntax? Or what am I missing here?

It's a fairly complicated entity that needs to be serialized and returned as json, thus I'd really like to use entityLoad, if possible.

Regards,
Greg

Cameron Childress

unread,
Aug 15, 2016, 9:02:16 PM8/15/16
to cf-or...@googlegroups.com
First I'll say that I tend to only use ORM for simple entity operations like "get > update > save" and try to avoid any HQL or more complicated associated entity stuff - it's just a total pain to debug. For anything where tables need to be joined I drop back down to plain ole SQL.

Having said that, try using the entitre participant not just it's ID. Like this:

rc.participant = EntityLoad('participants', { participantID = rc.id})
Logs = EntityLoad( "logs", { participant = rc.participant } );

Hibernate is smart enough to know that when you throw it an entire related entity that it needs to join on that ID column and will just do the rest for you.

-Cameron



--
You received this message because you are subscribed to the Google Groups "cf-orm-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cf-orm-dev+unsubscribe@googlegroups.com.
To post to this group, send email to cf-or...@googlegroups.com.
Visit this group at https://groups.google.com/group/cf-orm-dev.
For more options, visit https://groups.google.com/d/optout.



--
Cameron Childress
--
p:   678.637.5072
im: cameroncf

Gregory Thrush

unread,
Aug 19, 2016, 12:44:49 PM8/19/16
to cf-orm-dev
> To unsubscribe from this group and stop receiving emails from it, send an email to cf-orm-dev+...@googlegroups.com.
>
> To post to this group, send email to cf-or...@googlegroups.com.
>
> Visit this group at https://groups.google.com/group/cf-orm-dev.
>
> For more options, visit https://groups.google.com/d/optout.
>
>
>
>
>
> --
>
> Cameron Childress
> --
> p:   678.637.5072
> im: cameroncf
>
> facebook | twitter | google+

I took your suggestion and used a hql query which worked fine.
Reply all
Reply to author
Forward
0 new messages