Problem with ORM Service

Hi guys,

This is a hybrid ColdBox / ORM type question, but I think the answer is ORM related.

I have two entities.

Incident
IncidentEvent

events are a one-to-many relationship of Incident

{Incident Entity}

property name=“events” fieldtype=“one-to-many” cfc=“IncidentEvent” fkcolumn=“fk_incidentid” singularname=“event” cascade=“all-delete-orphan”;

{Incident Handler}

After creating an Incident I create an Incident Event and then return the incident status like so:

//create incident event

var incidentEvent = ormService.new(“IncidentEvent”);

// Populate Incident with the user’s input
BeanFactory.populateBean(target=incidentEvent,include='event_type,channel,incidentid,userid);

//save incident event
ORMService.save(incidentEvent);

//return the incident status
rc.results.setData(incidentService.getIncidentStatus(rc.incidentid,rc.userID));

…getIncidentStatus() looks like this:

struct function getIncidentStatus(required numeric IncidentID,numeric UserID) output=false{
var Incident = structNew();

if(isDefined(“arguments.UserID”)){
var qIncident = entityLoad(‘Incident’,{Incidentid=arguments.IncidentID,userid=arguments.UserID},true);
}else{
var qIncident = entityLoadByPK(‘Incident’,arguments.IncidentID);
}

if (!isNull(qIncident)){
Incident.id = qIncident.getIncidentID();
Incident.group = groupService.getGroup(qIncident.getGroupID());
Incident.dateCreated = qIncident.getDateCreated();

var incidentEvents = [];
if(arrayLen(qIncident.getEvents())){

for (i=1;i LTE ArrayLen(qIncident.getEvents());i=i+1) {
local.event = structNew();
local.event.type = qIncident.getEvents()[i].getEvent_Type();
local.event.user = qIncident.getEvents()[i].getUserID();
arrayAppend(incidentEvents,local.event);
}

}

Incident.events = incidentEvents;

}

return Incident;
}

CF is bombing when it tries to evaluate qIncident.getEvents() because the property does not exist or isn’t populated. Using CF Debugger I set a breakpoint after the qIncident call and looked at the variables of the object. Events was not listed.

After the failure if I make a subsequent call to getIncidentStatus(), the events property of Incident is Populated. So it appears that the ORMService.save(incidentEvent) call has not finished executing by the time i’m calling getIncidentStatus().

Any ideas what i’m doing wrong here?

Thanks.

Nolan

Can you post the error

Hi Luis,

I’m posting this on the ORM list as well.

My ORM settings are like so:

flushatRequestEnd = false,
automanagesession = false

and I added an explicit ORMFlush(); after the save. Still no dice.

And as Curt mentioned (on the ORM list), I believe ColdBox’s ORMService is using transactions under the hood.

This is the actual error that is produced…looks like a null pointer exception which seems right because it can’t find the events property. Although it doesn’t make sense (to me) why this is occurring.

{“NullPointerException”: {“Cause”:null,“Message”:null,“LocalizedMessage”:null,“StackTrace”:[{“FileName”:“Cast.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.Cast”,“LineNumber”:1343,“MethodName”:"_List"},{“FileName”:“CFPage.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.CFPage”,“LineNumber”:557,“MethodName”:“ArrayLen”},{“FileName”:"/Library/WebServer/Documents/myapp/common/model/IncidentService.cfc",“NativeMethod”:false,“ClassName”:“cfIncidentService2ecfc1213573963$funcGETINCIDENTSTATUS”,“LineNumber”:66,“MethodName”:“runFunction”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod”,“LineNumber”:472,“MethodName”:“invoke”},{“FileName”:“SilentFilter.java”,“NativeMethod”:false,“ClassName”:“coldfusion.filter.SilentFilter”,“LineNumber”:47,“MethodName”:“invoke”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod$ReturnTypeFilter”,“LineNumber”:405,“MethodName”:“invoke”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod$ArgumentCollectionFilter”,“LineNumber”:368,“MethodName”:“invoke”},{“FileName”:“FunctionAccessFilter.java”,“NativeMethod”:false,“ClassName”:“coldfusion.filter.FunctionAccessFilter”,“LineNumber”:55,“MethodName”:“invoke”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod”,“LineNumber”:321,“MethodName”:“runFilterChain”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod”,“LineNumber”:220,“MethodName”:“invoke”},{“FileName”:“TemplateProxy.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.TemplateProxy”,“LineNumber”:491,“MethodName”:“invoke”},{“FileName”:“TemplateProxy.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.TemplateProxy”,“LineNumber”:337,“MethodName”:“invoke”},{“FileName”:“CfJspPage.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.CfJspPage”,“LineNumber”:2360,“MethodName”:"_invoke"},{“FileName”:"/Library/WebServer/Documents/myapp/api/v01/handlers/Incident.cfc",“NativeMethod”:false,“ClassName”:“cfIncident2ecfc780776415$funcGETINCIDENT”,“LineNumber”:29,“MethodName”:“runFunction”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod”,“LineNumber”:472,“MethodName”:“invoke”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod$ArgumentCollectionFilter”,“LineNumber”:368,“MethodName”:“invoke”},{“FileName”:“FunctionAccessFilter.java”,“NativeMethod”:false,“ClassName”:“coldfusion.filter.FunctionAccessFilter”,“LineNumber”:55,“MethodName”:“invoke”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod”,“LineNumber”:321,“MethodName”:“runFilterChain”},{“FileName”:“UDFMethod.java”,“NativeMethod”:false,“ClassName”:“coldfusion.runtime.UDFMethod”,“LineNumber”:517,“MethodName”:“invoke”}…

Thanks.

Nolan

have you turned on hibernate logging in your instance so you can see what hibernate reports?:

I think the problem has to do with bi-directional relationships. I have a thread going on the ORM list which is providing me more insight.

Question though… does the BeanFactory.populateBean() work for properties which have relationships? i.e Incident has Events, and Events is a one-to-many property?

If so, can you point me in the direction of how to populate?

Thanks.

Nolan