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

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 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 \model folder or are there something else causing this issue? I have check to ensure the cases match.

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.

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;
}
}

And the error message would be handy as well.

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.

But normally with an error message like that you either have the Entity name wrong or you have the table name wrong.

Andrew,

If I place the model under /modules/solitary/model, then there are no issues with the relationship mapping . However if i place at the application root level, i.e. /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 \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

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”;

yes…i appended “solitary.” to the cfc parameter, i.e. it now reads: cfc=“solitary.model.services.Service”

Andrew,

Also in \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;
}
}

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.

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.

If the same model cfc works under \modules\solitary\model, and not under \model, then I think the error is not in the mapping definition.
That is, if I now move all the associated model cfc to \model, and do an ormReload, it will fail; however if I move them back to \modules\solitary\model, it will succeed.

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.

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

yep