Member functions do not work on ORM object method results

Description

When trying to access results from an ORM object via a member function, ex: array.each(), I get this: No matching Method/Function for org.hibernate.collection.PersistentBag.each(lucee.runtime.type.Closure) found.

Consider this general example where a persistent user object can have many roles.

User.cfc

component persistent="true" table="users" output="false" { property name="userId" fieldtype="id" ormtype="int" generator="native"; property name="name" ormtype="string" default=""; property name="roles" singularname="role" cfc="Role" fieldType="many-to-many" linkTable="user_roles" fkcolumn="roleId" inverseJoinColumn="userId"; public User function init() { return this; } }

Role.cfc

component displayname="Role" persistent="true" table="roles" output="false" { property name="roleId" fieldtype="id" ormtype="int" setter="false" generator="native"; property name="title" ormtype="string" default=""; property name="users" singularname="user" cfc="User" fieldType="many-to-many" linkTable="user_roles" fkcolumn="userId" inverseJoinColumn="roleId"; public Role function init() { return this; } }

This relationship will in turn create the function getRoles() in the user object which will return an array of role objects that I want to access.

The below code is what errors...
Note that this runs in ACF 11.

example.cfm

user = entityLoadByPK("User", 1); list = ""; user.getRoles().each(function(role) { list = listAppend(list, role.getTitle()); }); writeOutput(list);

Environment

Windows 8.1 / nginx / Tomcat 8.0.23 / Lucee 4.5.1.022 (WAR)

Attachments

1
  • 28 Jul 2015, 07:29 pm

Activity

Show:

Michael Offner 19 July 2017 at 16:24

this is already fixed

Michael Offner 19 July 2017 at 06:04

Lucee 5 support to loop any List objects like this out of the bag, because "PersistentBag" is a list object this works now just fine.

Luis Majano 27 October 2015 at 12:56

This is reproducible anywhere you return array of entities.

T Lingard 21 October 2015 at 14:51

This is happening with arrays from Postgres Array fields as well.

Type: Native Array (java.lang.String[])
No matching Method/Function for [[Ljava.lang.String;.each(lucee.runtime.type.Closure) found]]

As Brad mentioned, it has to be changed to ArrayImpl before using the array with member functions

Lucee Fer 28 July 2015 at 19:29
Edited

I figured this behavior too, and was about to open a new ticket. If it can help, I attach a full test case (case1.zip) I worked on to understand the issue...
NB: the problem occurs only after the EntitySave() call.

Duplicate

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 8 July 2015 at 22:48
Updated 19 July 2017 at 16:24
Resolved 19 July 2017 at 16:24

Flag notifications