Ok guys this is driving me crazy. I am trying to use ORM with a new Coldbox application but keep seeing duplicate columns being queried in my ORM logs when I call on my relationships.
Here’s the scoop:
Setup:
Railo 4.1.1
Coldbox 3.7.0
I have the following models:
models/Customer/Customer.cfc
models/Customer/CustomerService.cfc
models/Distributor/Distributor.cfc
models/Distributor/DistributorService.cfc
My service files simply extend coldbox.system.orm.hibernate.VirtualEntityService for easy querying.
Rules:
One distributor can have many customers. Many customers can have one distributor.
Here’s the files:
Distributor.cfc:
component persistent=“true” table=“distributors” {
// Primary key
property name=“distributorID” fieldtype=“id” generator=“native”;
// Relationships
property name=“Customers” cfc=“Customer.Customer” fieldtype=“one-to-many” fkcolumn=“distributorID” inverse=“true”;
}
Customer.cfc:
component persistent=“true” table=“customers” {
// Primary key
property name=“customerID” fieldtype=“id” generator=“native”;
// Relationship
property name=“Distributor” cfc=“Distributor.Distributor” fieldtype=“many-to-one” fkcolumn=“distributorID”;
// Fields
property name=“firstName”;
property name=“lastName”;
}
When I call this code:
c = customerService.newCriteria().list();
writeDump(c[1].getDistributor());
Here’s the ORM SQL Logs:
Hibernate:
select
distributo0_.distributorID as distribu1_508_0_
from
distributors distributo0_
where
distributo0_.distributorID=?
Hibernate:
select
customers0_.distributorID as distribu4_508_1_,
customers0_.customerID as customerID1_,
customers0_.customerID as customerID509_0_,
customers0_.firstName as firstName509_0_,
customers0_.lastName as lastName509_0_,
customers0_.distributorID as distribu4_509_0_
from
customers customers0_
where
customers0_.distributorID=?
Notice customerID and distributorID are retrieved twice. What am I doing wrong? I have read the Adobe ORM documentation at least 5 times already and still can’t figure this out. I am afraid this means I having something configured incorrectly and will result in problems when I try persisting objects and whatnot.
Thanks,
Grant