Skip to main content
pnahtanoj
Participant
February 28, 2016
Answered

many-to-many relationship not saving linktable

  • February 28, 2016
  • 1 reply
  • 414 views

Got a bit of a legacy app that previously had flushAtRequestEnd set to true.  We've flipped the flag, and now our many-to-many relationships aren't working properly.  The individual records save fine, BUT the link table records are not being created.  Here's how the entities are basically set up.

component persistent="true" table="Encounters" {

...

    property

        name="CaseFollowUps"

        singularname="CaseFollowUp"

        fieldtype="many-to-many"

        cfc="FollowUp_NEW"

        linktable="EncounterFollowUp"

        fkcolumn="EncounterID"

        inversejoincolumn="FollowUpID";

....

    public void function addCaseFollowUp( fu ) {

        ArrayAppend( variables.CaseFollowUps, fu );

        arguments.fu.addEncounter( this );

    }

...

}

component persistent="true" table="FollowUp_NEW" {

    property

        name="Encounters"

        singularname="Encounter"

        fieldtype="many-to-many"

        cfc="Encounter"

        linktable="EncounterFollowUp"

        fkcolumn="FollowUpID"

        inversejoincolumn="EncountersID";

}

I'm calling the 'addCaseFollowUp' convenience method on a preexisting Encounter within a transaction.  No errors thrown.  I see this Hibernate code for inserting the FollowUp_NEW record:

insert

  into

  FollowUp_NEW

  (Note, UserDateTime, UpdateDateTime, CreateDateTime, DispositionID, FollowUpRequestID, CommunicationTypeID, UserID)

  values

  (?, ?, ?, ?, ?, ?, ?, ?)

But I don't see a Hibernate query for inserting the EncounterFollowUp record.


Suggestions?

    This topic has been closed for replies.
    Correct answer BKBK

    pnahtanoj wrote:

    But I don't see a Hibernate query for inserting the EncounterFollowUp record.


    Is there perhaps a query that updates EncounterFollowUp? If there is none either, then run the code as a trasaction. That woud rule out the fact the ORM session ended prematurely.

    1 reply

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    March 6, 2016

    pnahtanoj wrote:

    But I don't see a Hibernate query for inserting the EncounterFollowUp record.


    Is there perhaps a query that updates EncounterFollowUp? If there is none either, then run the code as a trasaction. That woud rule out the fact the ORM session ended prematurely.

    pnahtanoj
    pnahtanojAuthor
    Participant
    March 7, 2016

    I don't recall as it's been a bit, but it's since been fixed.  I believe transactions may have been part of it, but I can't remember.  Will mark answer as correct.