An association from the <table-name> refers to an unmapped class

139 views
Skip to first unread message

Yieng

unread,
Jun 24, 2015, 1:06:29 AM6/24/15
to col...@googlegroups.com
Hi,

I am trying to add relationships to a component (entity) in Coldbox, in particular many-to-many and one-to-many, and getting one of the following errors:

  • An association from the <table-name> refers to an unmapped class (many-to-many relationship mapping)
  • Association references unmapped class (one-to-many relationship mapping)

After I added the relationship and perform an ormReload, I see one of the above errors. If I comment out the relationship and do an ormReload, everything is fine.


The orm settings in Application.cfc:


    this.ormSettings = {
           dialect = "MicrosoftSQLServer",
           dbcreate = "update",
           eventhandling = true,
           flushAtRequestEnd = false,
           cfclocation = ["model","modules/solitary/model"]
     };


The relationship mapping in under 'solitary' is fine, i.e. the many-to-many for users-roles.


Is Coldbox not picking up the model in the <app-root>\model folder or are there something else causing this issue? I have check to ensure the cases match.




Andrew Scott

unread,
Jun 24, 2015, 1:32:43 AM6/24/15
to col...@googlegroups.com
ORM entity properties and relationships have nothing to do with ColdBox. The only thing ColdBox does if you use Wirebox to inbect anything into the Entity.

Maybe giving us an example of what your trying to do. But normally with an error message like that you either have the Entity name wrong or you have the table name wrong.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


--
--
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
For News, visit http://blog.coldbox.org
For Documentation, visit http://wiki.coldbox.org
For Bug Reports, visit https://ortussolutions.atlassian.net/browse/COLDBOX
---
You received this message because you are subscribed to the Google Groups "ColdBox Platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to coldbox+u...@googlegroups.com.
To post to this group, send email to col...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/coldbox/854c5781-c31d-4fbb-9748-86beb848ca89%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yieng

unread,
Jun 24, 2015, 2:54:35 AM6/24/15
to col...@googlegroups.com
Andrew,

Here is a sample:

Client.cfc (app-root\model\clients\)
component persistent="true" extends="solitary.model.BaseEntity" table="clients" {
    property name="clientID" fieldtype="id" generator="identity" setter="false";
    property name="title" sqltype="nvarchar" length="10";
    property name="firstname" sqltype="nvarchar" length="100";
    property name="lastname" sqltype="nvarchar" length="100";
    property name="services" fieldtype="many-to-many" cfc="model.services.Service" singularname="service" fkcolumn="clientID" inversejoincolumn="serviceID" linktable="clients_services";
    property name="phones" fieldtype="one-to-many" cfc="model.phones.Phone" singularname="phone" fkcolumn="clientID" type="array";

    public Client function init(){
        services = [];
        return this;
    }
}

Service.cfc (app-root\model\services\):
component persistent="true" extends="solitary.model.BaseEntity" table="services" {
   
    property name="serviceID" column="serviceID" fieldtype="id" generator="identity" setter="false";
    property name="name" notempty="true" min="3" sqltype="nvarchar" length="20";
    property name="desc" sqltype="nvarchar" length="30";
     
    public Service function init(){
        clients = [];
        return this;

Andrew Scott

unread,
Jun 24, 2015, 4:15:00 AM6/24/15
to col...@googlegroups.com
And the error message would be handy as well.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Yieng

unread,
Jun 24, 2015, 7:42:32 AM6/24/15
to col...@googlegroups.com
One of the below errors:
  • An association from the clients_services refers to an unmapped class:
    (for the many-to-many relationship mapping)
  • Association references unmapped class:
    (for a one-to-many relationship mapping)
If you need the stack trace, I will need to recreate and supply them tomorrow. But it didn't shed anymore light for me.

Andrew Scott

unread,
Jun 24, 2015, 9:59:09 AM6/24/15
to col...@googlegroups.com
But normally with an error message like that you either have the Entity name wrong or you have the table name wrong.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Yieng

unread,
Jun 24, 2015, 8:58:37 PM6/24/15
to col...@googlegroups.com
Andrew,

If I place the model under <app-root>/modules/solitary/model, then there are no issues with the relationship mapping . However if i place at the application root level, i.e. <app-root>/model/, it fails.

Seems like it is not picking up the model at the application root level for orm relationship mappings. But if i commented out the relationship part of the model, it does successfully created the tables for models in the application level, i.e.models in <app-root>\model\.

So is the following correct (in particular the cfclocation parameter) for ormSettings in application.cfc:


    this.ormSettings = {
           dialect = "MicrosoftSQLServer",
           dbcreate = "update",
           eventhandling = true,
           flushAtRequestEnd = false,
           cfclocation = []
     };

Are there anything else I have mis-configured?

Yieng

Andrew Scott

unread,
Jun 24, 2015, 9:18:12 PM6/24/15
to col...@googlegroups.com
And when you make that change did you also make changes to these two fields?

property name="services" fieldtype="many-to-many" cfc="model.services.Service" singularname="service" fkcolumn="clientID" inversejoincolumn="serviceID" linktable="clients_services";
    property name="phones" fieldtype="one-to-many" cfc="model.phones.Phone" singularname="phone" fkcolumn="clientID" type="array";

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Yieng

unread,
Jun 24, 2015, 9:49:06 PM6/24/15
to col...@googlegroups.com
yes..i appended "solitary." to the cfc parameter, i.e. it now reads: cfc="solitary.model.services.Service"

Yieng

unread,
Jun 24, 2015, 9:55:56 PM6/24/15
to col...@googlegroups.com
Andrew,

Also in <app-root>\model\clients\clientService.cfc, is my injection correct (i.e. inject="model:clientService"), see below:

component extends="coldbox.system.orm.hibernate.VirtualEntityService" singleton {
    property name="clientService"    inject="model:clientService";
       
    public ClientService function init(){
        super.init(entityName="Client");
        return this;

Andrew Scott

unread,
Jun 24, 2015, 9:57:08 PM6/24/15
to col...@googlegroups.com
Ok I am asking because if you change the Entity location then the CFC property needs to be adjusted to that location and I assume Solitary as a mapping defined in the Application.cfc

Also may pay to read the ColdFusion documentation when it comes to Entity relationships.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Andrew Scott

unread,
Jun 24, 2015, 9:59:59 PM6/24/15
to col...@googlegroups.com
As the error is an Entity error, I doubt it is getting that for. But as long as the model is a scanned Wirebox folder it will get injected.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Yieng

unread,
Jun 24, 2015, 11:39:57 PM6/24/15
to col...@googlegroups.com
If the same model cfc works under <app-root>\modules\solitary\model, and not under <app-root>\model\, then I think the error is not in the mapping definition.
That is, if I now move all the associated model cfc to <app-root>\model\, and do an ormReload, it will fail; however if I move them back to <app-root>\modules\solitary\model, it will succeed.

Andrew Scott

unread,
Jun 25, 2015, 12:20:47 AM6/25/15
to col...@googlegroups.com
But when you move them what are you putting in the CFC attribute on the property, again this is very basic ORM relationship stuff. I suggest reading the ColdFusion docs on those Entity properties.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/


Yieng

unread,
Jun 25, 2015, 1:09:09 AM6/25/15
to col...@googlegroups.com
Thanks for your suggestions.

It is fixed now!!
Solution:
The path to the cfc parameter in the relationship definition must be absolute from the webroot, i.e. cfc="full.path.from.webroot.model.services.Service".

Yieng

Andrew Scott

unread,
Jun 25, 2015, 1:28:57 AM6/25/15
to col...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages