ORM postNew and default values

Hi,

We have a situation where we want to initialize entities with some default properties, but these properties are many to one entity relations, so no default strings or integers possible.
So we thought we use the postNew handler in coldbox.system.remote.ColdboxProxy CFIDE.orm.IEventHandler. This way we can initialize these many to one properties by eventhandling.
Because of the name postNEW I thought this handler was executed just after a NEW entity was created. But it is not completely true, it is executed AFTER populaiton of the entity in the ORMService.new method… This event is not a default hibernate event, but called by ColdBox in the BaseORMService.new() method.

Consider this code

`
myproperties={Name=“mydomainname”,DomainStatus=SomeNoneDefaultStatus};
myDomain=ormservice.new(“Domain”,myproperties);
writedump(myDomain);
//will NOT result in a DOMAINSTATUS=SomeNoneDefaultStatus but DOMAINSTATUS=DEFAULTSTATUS when ORM eventhandling is in place
//the following example will actually result in DOMAINSTATUS=SomeNoneDefaultStatus
MyDomain = ormservice.new(“Domain”);
ormService.populate(MyDomain,myproperties);
writedump(myDomain);

`

So the order of events when using orm.new with properties is: new entity is created, then entity will be populated, and then the postNew handler is called, in this case effectively overwriting our just added non-default properties with some default ones.

For me this is a bit confusing, so I was wondering, is this by design?
Of course we could easyly override the ormservice.new method and call the eventhandler in this method just before populating. Just wondering if I am missing something in this scenario?

Regards,

Wil
.

Example

`

component persistent=“true”
table=“mydomains”

entityname=“Domain”
{

property name=“Id” fieldtype=“id” ormtype=“integer” generator=“increment”;

property name=“Name” ormtype=“string” notnull=“true”;

//many to one

property name=“DomainStatus” fieldtype=“many-to-one” fkcolumn=“Status_fk” cfc=“DomainStatus” lazy=“true” notnull=“true”;
}

`

component persistent=“true”
table=“masterdomainstatus”
entityname=“DomainStatus”
{

// Primary Key
property name=“Id” fieldtype=“id” ormtype=“integer” generator=“increment”;
// Properties
property name=“Name” ormtype=“string” notnull=“true”;
property name=“Active” ormtype=“boolean” notnull=“true” default=“false”;

}

`

Obviously there is more code, but we want to initialize a new status

`