Duplicate ORM Columns Help Please

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

Hard to view everything in detail on my phone, but it seems to me that o2m/m2o are the wrong relationship choices. I would think this would be either m2m or two more relationships with an intermediary class.

HTH

That should have read:

or two m2o relationships with an intermediary class

Thanks. Figured this out guys. It only occurs when doing a cfdump on getDistributor() from a customer object because the distributor also contains a relationship the customer record again - which apparently causing hibernate to do this odd duplicate column thing.

Doing something like this does not generate any duplicate columns:

c = customerService.newCriteria().list();
writeDump(c[1].getDistributor().getDistributorID());

All is well :slight_smile:

Thanks,

Grant