Coldbox 3.6.0 ORM problem

I cheated and posted this on the end of another question. Since it didn’t get any response, I thought it best to post a new topic.

I copied the example from http://wiki.coldbox.org/wiki/Models.cfm (under ORM) exactly because I was having some issues with mine. It works to list and save, however when I try delete I get “Application Execution Exception Error Type: java.lang.NumberFormatException : 0 Error Messages: For input string: “Contact”” and when I edit, it just creates a new record instead of updating the existing one. Any ideas? I know this is something relatively stupid, I’m just not seeing it. I appreciate all the help. I’m trying to get comfortable with ORM in CB so I can convert a few of my existing ColdBox apps over.

Thanks again,
Scott

Is the primary key getting set into the object? Also, please provide a stack trace of the error and show us the code.

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Looks like you are not sending through the id of the item you want to delete/update. What does it give you when you dump RC in your delete and save handler methods?

Thanks Brad,The primary key does appear to be gettimg set, yes. As for the code, it is exactly the same as the code on the page http://wiki.coldbox.org/wiki/Models.cfm under ORM. I copied it line for line (and verified it) The stack trace is as follows and the rc and prc are after that. It appears to be passing the id over as expected.

For input string: "skill"
	at java.lang.NumberFormatException.forInputString(Unknown Source):-1
	at java.lang.Integer.parseInt(Unknown Source):-1
	at java.lang.Integer.(Unknown Source):-1
	at org.hibernate.type.IntegerType.fromStringValue(IntegerType.java:94):94
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):-2
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source):-1
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source):-1
	at java.lang.reflect.Method.invoke(Unknown Source):-1
	at railo.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:37):37
	at railo.runtime.reflection.Reflector.callMethod(Reflector.java:799):799
	at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:732):732
	at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1506):1506
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf._5(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc:1249):1249
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf.udfCall(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:275):275
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:608):608
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:498):498
	at railo.runtime.SuperComponent.callWithNamedValues(SuperComponent.java:86):86
	at railo.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:749):749
	at railo.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1521):1521
	at coldbox.system.orm.hibernate.virtualentityservice_cfc$cf._3(/var/www/coldbox/system/orm/hibernate/VirtualEntityService.cfc:220):220
	at coldbox.system.orm.hibernate.virtualentityservice_cfc$cf.udfCall(/var/www/coldbox/system/orm/hibernate/VirtualEntityService.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.call(UDFImpl.java:284):284
	at railo.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:775):775
	at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:723):723
	at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1506):1506
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf._3(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc:584):584
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf.udfCall(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:275):275
	at railo.runtime.type.scope.ArgumentImpl.callWithNamedValues(ArgumentImpl.java:546):546
	at railo.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:749):749
	at railo.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1521):1521
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf._6(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc:1412):1412
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf.udfCall(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.call(UDFImpl.java:284):284
	at railo.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:775):775
	at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:723):723
	at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1506):1506
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf._3(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc:576):576
	at coldbox.system.orm.hibernate.baseormservice_cfc$cf.udfCall(/var/www/coldbox/system/orm/hibernate/BaseORMService.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:275):275
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:608):608
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:498):498
	at railo.runtime.SuperComponent.callWithNamedValues(SuperComponent.java:86):86
	at railo.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:749):749
	at railo.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1521):1521
	at coldbox.system.orm.hibernate.virtualentityservice_cfc$cf._2(/var/www/coldbox/system/orm/hibernate/VirtualEntityService.cfc:139):139
	at coldbox.system.orm.hibernate.virtualentityservice_cfc$cf.udfCall(/var/www/coldbox/system/orm/hibernate/VirtualEntityService.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.call(UDFImpl.java:284):284
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:607):607
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:490):490
	at railo.runtime.ComponentImpl.call(ComponentImpl.java:1781):1781
	at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:723):723
	at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1506):1506
	at scott.handlers.skills_cfc$cf.udfCall(/var/www/scott/handlers/skills.cfc:16):16
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:275):275
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:608):608
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:490):490
	at railo.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1796):1796
	at railo.runtime.tag.Invoke.doComponent(Invoke.java:209):209
	at railo.runtime.tag.Invoke.doEndTag(Invoke.java:182):182
	at coldbox.system.web.controller_cfc$cf._6(/var/www/coldbox/system/web/Controller.cfc:756):756
	at coldbox.system.web.controller_cfc$cf.udfCall(/var/www/coldbox/system/web/Controller.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.call(UDFImpl.java:284):284
	at railo.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:775):775
	at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:723):723
	at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1506):1506
	at coldbox.system.web.controller_cfc$cf._5(/var/www/coldbox/system/web/Controller.cfc:640):640
	at coldbox.system.web.controller_cfc$cf.udfCall(/var/www/coldbox/system/web/Controller.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:275):275
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:608):608
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:490):490
	at railo.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1800):1800
	at railo.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:749):749
	at railo.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1521):1521
	at coldbox.system.coldbox_cfc$cf._1(/var/www/coldbox/system/Coldbox.cfc:236):236
	at coldbox.system.coldbox_cfc$cf.udfCall(/var/www/coldbox/system/Coldbox.cfc):-1
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.call(UDFImpl.java:284):284
	at railo.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:775):775
	at railo.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:723):723
	at railo.runtime.PageContextImpl.getFunction(PageContextImpl.java:1506):1506
	at scott.application_cfc$cf.udfCall(/var/www/scott/Application.cfc:69):69
	at railo.runtime.type.UDFImpl.implementation(UDFImpl.java:103):103
	at railo.runtime.type.UDFImpl._call(UDFImpl.java:371):371
	at railo.runtime.type.UDFImpl.call(UDFImpl.java:284):284
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:607):607
	at railo.runtime.ComponentImpl._call(ComponentImpl.java:490):490
	at railo.runtime.ComponentImpl.call(ComponentImpl.java:1781):1781
	at railo.runtime.listener.ModernAppListener.call(ModernAppListener.java:346):346
	at railo.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:107):107
	at railo.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:18):18
	at railo.runtime.PageContextImpl.execute(PageContextImpl.java:2255):2255
	at railo.runtime.PageContextImpl.execute(PageContextImpl.java:2222):2222
	at railo.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:315):315
	at railo.loader.servlet.CFMLServlet.service(CFMLServlet.java:29):29
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728):728
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305):305
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210):210
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222):222
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123):123
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472):472
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171):171
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99):99
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118):118
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407):407
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004):1004
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589):589
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310):310
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source):-1
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source):-1
	at java.lang.Thread.run(Unknown Source):-1
id: 2
event: skills.delete
namespacerouting: N/A
namespace: N/A

Private Collection
cbox_incomingcontexthash: E619EA5ED5B7FDE1A5D02D0CB5C67445
currentroutedurl: skills/delete/id/2/
currentroute:

Scott, can you show the snippet of code you’re using to execute this method which is producing this error?

On a whim, I tried a test out, and was able to recreate the error. The issue appears to be that you are calling the deleteByID method in the BaseORMService style:

// Base ORM Service…needs entityName as argument
{ORMService}.deleteByID( “SomeEntityName”, “SomeID”, …);

Since you are using a Virtual Entity Service, however, it’s unnecessary to pass the entity name, since you’ve already established the entity’s identity in setting up the VES (in the init()). So then, when you pass unnamed arguments to deleteByID, the first positional argument should be the ID, since the entity name will be automatically resolved by the VES:

// Virtual Entity Service…doesn’t need entityName as argument
SomeVEService.deleteByID( “SomeID” );

Hope this helps

But when I’m calling the deleteById from the handler, it’s as such:

function delete(event,rc,prc){
event.paramValue(“id”,0);
entityNew(“Contact”).deleteByID( rc.id );
getPlugin(“MessageBox”).info(“Contact Removed!”);
setNextEvent(“contacts”);
}

so I’m not passing the entity as the first argument.

Ok, I see you’re using ActiveEntity. When I try this same thing, it works as expected. Can you share the code for your Contact persistent entity?

component persistent=“true” table=“contacts” extends=“coldbox.system.orm.hibernate.ActiveEntity”{

// Primary Key

property name=“contactID” fieldtype=“id” column=“contactID” generator=“native” setter=“false”;

// Properties

property name=“firstName” ormtype=“string”;

property name=“lastName” ormtype=“string”;

property name=“email” ormtype=“string”;

// validation

this.constraints = {

firstName = {required=true},

lastName = {required=true},

email = {required=true, type=“email”}

};

}

FYI, this example is letter for letter the same as the example at the bottom of http://wiki.coldbox.org/wiki/Models.cfm under the header “Coding: ActiveEntity Style” That’s why I’m sure it is just something stupid that I’m overlooking.

Thanks for your help.

Scott

component persistent=“true” table=“contacts” extends=“coldbox.system.orm.hibernate.ActiveEntity”{

// Primary Key

property name=“contactID” fieldtype=“id” column=“contactID” generator=“native” setter=“false”;

// Properties

property name=“firstName” ormtype=“string”;

property name=“lastName” ormtype=“string”;

property name=“email” ormtype=“string”;

// validation

this.constraints = {

firstName = {required=true},

lastName = {required=true},

email = {required=true, type=“email”}

};

}

FYI, this example is letter for letter the same as the example at the bottom of http://wiki.coldbox.org/wiki/Models.cfm under the header “Coding: ActiveEntity Style” That’s why I’m sure it is just something stupid that I’m overlooking.

Thanks for your help.

Scott

ORM is working for list and insert It even created the table in the first place like it should. It’s just not working right for delete/update. Just in case, below are the relevant sections of those files.

Scott

Application.cfc:

// Enable ORM

this.ormEnabled = true;

// ORM Datasource (The only difference from the example)

this.datasource = “career”;

// ORM configuration settings

this.ormSettings = {

// Location of your entities, default is your convention model folder

cfclocation = [“model”],

// Choose if you want ORM to create the database for you or not?

dbcreate “update”,

// Log SQL

logSQL = true,

// Don’t flush at end of requests, let Active Entity manage it for you

flushAtRequestEnd = false,

// Don’t manage session, let Active Entity manage it for you

autoManageSession = false,

// Active ORM events

eventHandling = true,

// Use the ColdBox WireBox Handler for events

eventHandler = “coldbox.system.orm.hibernate.WBEventHandler”

};

Coldbox.cfc

// Setup ORM

orm = { injection = {enabled=true} };

You don’t want to be using ColdFusion entityNew() with the deleteById() instead you want to use the new().deleteById() instead.

I get a “No matching function [NEW] found” if I try that.

Yeah I think the docs need to be changed here, if this is in the handler then you might need to DI the ActiveEntity and then use that.

Not sure why the docs are showing that you can deleteById() with the entityNew() unless there is some magic happening in the event Handler, but as far as creating a new entity there is no event for that.

I think that’s what ActiveEntity does, though. It takes regular entities and adds the Virtual Entity Services to it so that you can do more with your entity than you can with generic CF entities. I typically use concrete services, but in my test of the use case above, the functionality (as described) was working as documented.