Question

In ColdFusion 9.0.2 I am trying to map two one-to-one relationships\properties (createdBy and modifiedBy) in an entity (posting) to the same table\entity (user) and on the same column (userID) and I'm encountering the following error:

Repeated column in mapping for entity: posting column: createdBy (should be mapped with insert="false" update="false")

I need both of these relationship to be modifiable for when I change the creator and the user that modified the posting. If I remove one of the relationships, createdBy or modifiedBy, from the posting entity then there are no issues so it seems like CF and or ORM doesn't like having these two properties pointing to the same column of the other entity.

SQL with FK Constraints

CREATE TABLE posting (
    postingID int IDENTITY (1,1) NOT NULL,
    name varchar(35) NOT NULL,
    createdBy int NOT NULL,
    modifiedBy int NOT NULL,

    PRIMARY KEY (postingID),
    CONSTRAINT fk_postingCreatedBy FOREIGN KEY (createdBy) REFERENCES user(ID),
    CONSTRAINT fk_postingModifiedBy FOREIGN KEY (modifiedBy) REFERENCES user(ID)
);

Posting Entity with Relationships

component persistent="true" table="posting" schema="dbo" output="false" {
    // properties
    property name="postingID" type="numeric" fieldtype="id" generator="identity";
    property name="name" type="string";

    // relationships
    property name="createdBy" fieldtype="one-to-one" cfc="user"; 
    property name="modifiedBy" fieldtype="one-to-one" cfc="user";
}

User Entity

component persistent="true" table="user" schema="dbo" output="false" {
    // properties
    property name="userID" column="ID" type="numeric" fieldtype="id" generator="identity";
    property name="firstName" type="string";
    property name="lastName" type="string";
}

I've tried several things to workaround this to no avail. I also cannot find any help with this specific to ColdFusion ORM, even other questions/postings in other language/uses of Hibernate that I've found don't match my specific scenario.

Any help or information is greatly appreciated!

Was it helpful?

Solution 2

Similar to the previous answer, you likely don't want a one-to-one relationship here. Unless for some reason a user is only ever able to make one post. You more likely actually want a many-to-one.

property name="createdBy" fieldtype="many-to-one" cfc="user" fkcolumn="createdBy";
property name="modifiedBy" fieldtype="many-to-one" cfc="user" fkcolumn="modifiedBy";

This allows each user to have many posts, but each post to only have one user.

OTHER TIPS

Try:

// relationships
property name="createdBy" fieldtype="one-to-one" cfc="user" fkcolumn="createdBy"; 
property name="modifiedBy" fieldtype="one-to-one" cfc="user" fkcolumn="modifiedBy";

If that doesn't work, try many-to-one. It has less restrictions and easier to work with.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top