ORMService.save()

Hi guys,

I’m attempting to use CB’s ORMService to populate and save a form post. The ORMService is injected into my handler and my handler function looks like this:

var myUser = populateModel( ORMService.new(“myUser”) );
//save the user to the group
ORMService.save(‘myUser’);

The MyUser entity looks like this:

component persistent=“true” table=“myUser” accessors=“true”{

property name=“id” fieldtype=“id” generator=“native”;
property name=“groupid” column=“fk_groupid”;
property name=“userid” column=“fk_userid”;
property name=“active”;
property name=“datecreated” ormtype=“timestamp” type=“string”;
property name=“dateremoved” ormtype=“timestamp” type=“string”;

public void function preInsert(){
variables.active = 1;
variables.datecreated = now();
}

}

When I execute the handler I receive the following error:

Application Execution ExceptionError Type: Application : [N/A]

**Error Messages:**coldfusion.orm.hibernate.HibernatePersistenceManager$InvalidEntityException: Object passed is not a valid entity.

Any ideas?

Thanks,

Nolan

The save method expects an object, whereas you have passed a string. So instead of:

ORMService.save(‘myUser’);

do:

ORMService.save( myUser );

doh! Thanks John.

Guess I need another cup of coffee!

Nolan

Please. grab me a cup too :slight_smile:

Also accessors=”true” is not needed on Entities either, this is automatic for these type of objects.

Regards,

Andrew Scott

http://www.andyscott.id.au/