• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ORM children removal

New Here ,
Feb 01, 2016 Feb 01, 2016

Copy link to clipboard

Copied

I'm running into some problems with a relatively simple task.

Application.cfc

component {

    THIS.datasource = "xmdlocaldevdb";

    THIS.name = "TESTING"; // MUST BE SAME AS TOP LEVE APP

    THIS.ormsettings.cfclocation = "/xmdroot/model/beans";

    THIS.environmentName = "TESTING";

    THIS.ormenabled = "true";

    THIS.ormsettings.cfclocation = "/xmdtestroot/model/beans";

    THIS.ormsettings.logSQL = "true";

    THIS.ormSettings.dbCreate = "none";

    THIS.ormsettings.eventhandling = true;

}

Parent.cfc

component persistent="true" table="Parent" {

    property name="id" fieldtype="id" column="ParentID" generator="identity";

    property name="Title" type="string";

    property

        name="Childs"

        fieldtype="one-to-many"

        cfc="Child"

        singularname="Child"

        fkcolumn="ChildID";

    public void function removeChildren(){

        if( !IsNull( this.getChilds() ) ) {

            ArrayClear( this.getChilds() );

        }

    }

}

Child.cfc

component persistent="true" table="Child" {

    property name="id" fieldtype="id" column="ChildID"  generator="identity";

    property

        name="Parent"

        fieldtype="many-to-one"

        cfc="Parent"

        fkcolumn="ParentID";

}

create.cfm:

ormReload();

parent = new xmdtestroot.model.beans.Parent();

parent.setTitle('Title One');

child = new  xmdtestroot.model.beans.Child();

child.setParent(parent);

parent.addChild(child);

entitySave(parent);

entitySave(child);

modify.cfm:

ormReload();

parent = entityLoad('Parent', 15, true);

parent.setTitle('Title - MOD');

parent.removeChildren();

--------

All pretty straightforward, I think? The create file runs fine, records created in the db correctly.  The modify file is throwing:

Column 'ChildID' cannot be null

I've read in numerous places that this should work.  I'm hoping someone can point out my obvious mistake.

As a note, I'm aware that the flushAtRequestEnd flag is left defaulted to true - this is a legacy app that's, unfortunately, unlikely to change in that regard soon...

Thanks,

Jonathan

Views

203

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2016 Feb 01, 2016

Copy link to clipboard

Copied

FWIW, I'm seeing this in the hibernate logs:

27002/01 12:16:49 [catalina-exec-2] HIBERNATE DEBUG -
271update
272Child
273set
274ChildID=null
275where
276ChildID=?
27702/01 12:16:49 [catalina-exec-2] HIBERNATE ERROR - Column 'ChildID' cannot be null
27802/01 12:16:49 [catalina-exec-2] HIBERNATE ERROR - Could not synchronize database state with session

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 01, 2016 Feb 01, 2016

Copy link to clipboard

Copied

LATEST

Finding some answers, but not total clarity.  I just downloaded the Whish ORM book, and it's shedding a little light, but I'm still seeing a few things I don't understand.


1) If I put inverse="true" in the Parent's one-to-many definition of Childs (as suggested in the ORM book), clearing the children doesn't do anything, weirdly.  If, instead, I put it on the Child's definition of Parent, I see the children's IDs set to NULL on removal.  Does that correct?


2) If I want the child records to actually go away in the DB, I'll need to actually call EntityDelete on them, correct?  For some reason I'd figured that removeChild would take care of that for you.


Anyhow, all clarification welcomed.  I'll continue reading the Whish book, as well.  Thanks.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation