Issue #946: ArrayIndexOutOfBounds with Critera API and function call

Type: Bug ReoprtVersion: 1.4.0Priority: HighStatus: ClosedReplies: 3
#1

Hello,

This is getting really frustrating sorry but we're close before delivering our app to our customer and went against a show-stopper again. We're building a simple query with the criteria api. What we have is something like (pseudo code)

class TestEntity
{
public Integer getAge()
{
return 100;
}
};

Create Selection Query (Critera-API) from * TestEntity and add
WHERE class with CriteraBuilder.function("$1.getAge", Integer.class) ($1 is a valid path we've goot from our root selector).

NOTE: Doing "$1.getAge()" does produce the same error

When trying to create a query from the criteria we get this:

11:20:06,538 ERROR .. Servlet.service() for servlet .. threw exception: java.lang.ArrayIndexOutOfBoundsException: 0
at com.objectdb.jpa.criteria.JpqlWriter.writeList(JpqlWriter.java:110) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.JpqlWriter.writeFunction(JpqlWriter.java:130) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.Expressions$c.writeJpql(Expressions.java:262) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.JpqlWriter.write(JpqlWriter.java:94) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.Expressions$b.writeJpql(Expressions.java:211) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.JpqlWriter.write(JpqlWriter.java:90) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.Expressions$k.writeJpql(Expressions.java:734) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.JpqlWriter.write(JpqlWriter.java:94) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.Expressions$k.writeJpql(Expressions.java:730) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.JpqlWriter.write(JpqlWriter.java:94) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.AbstractQueryImpl.writeJpql(AbstractQueryImpl.java:351) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.criteria.CriteriaQueryImpl.writeJpql(CriteriaQueryImpl.java:274) [objectdb-2.4.4.jar:]
at com.objectdb.jpa.EMImpl.createQuery(EMImpl.java:897) [objectdb-2.4.4.jar:]

Doing exactly the same on a map property with an argument works without troubles!??

 

#2

There was a problem with a function with no arguments.

Please try build 2.4.4_07 that should fix this exception.

Thank you for this report.

ObjectDB Support
#3

This is still not working in 2.4.5_08. The exception mentioned before no longer comes, however the method is not found, he now says when executing:

15:20:03,104 ERROR Servlet.service() for servlet UIApplication threw exception: com.objectdb.o.UserException: Method 'getAge' is not found in type 'TestEntity_3'
at com.objectdb.o.MSG.d(MSG.java:61) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.MCN.aC(MCN.java:177) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.MCN.<init>(MCN.java:103) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QMR.b(QMR.java:86) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.A(QNF.java:865) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.z(QNF.java:755) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.k(QNF.java:257) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.q(QNF.java:513) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.k(QNF.java:188) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.t(QNF.java:606) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.t(QNF.java:600) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.k(QNF.java:217) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QNF.j(QNF.java:134) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QRC.z(QRC.java:321) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QRC.v(QRC.java:212) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QRC.u(QRC.java:166) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.QRM.U5(QRM.java:248) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.MST.U5(MST.java:959) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.WRA.U5(WRA.java:291) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.WSM.U5(WSM.java:113) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.STC.r(STC.java:449) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.SHN.aj(SHN.java:489) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.SHN.K(SHN.java:156) [objectdb-2.4.4_08.jar:]
at com.objectdb.o.HND.run(HND.java:132) [objectdb-2.4.4_08.jar:]
at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_37]

The expression is created like mentioned in the initial issue so the method is there.

The only thing is that we're having an inheritance hierarchy like

class TestEntity_1
{
public Integer getAge()
{
return 100;
}
};

class TestEntity_2 extends TestEntity_1
{
};

class TestEntity_3 extends TestEntity_2
{
};

We're actually selecting from type "TestEntity_3" and building the function expression with 

CriteraBuilder.function("$1.getAge", Integer.class) ($1 is a valid path we've goot from our root selector)

I cannot create yet another sample as creating samples takes quite some time and I hope it can be resolved by you without as we're so short before final release of our software to our customer.

#4

Using user defined methods in queries is not recommended because:

  • It is non standard JPA extension.
  • It is inefficient (slow).

But it should work if the method exists and available, including on the server side. You have to add the relevant classes (and possibly all your application jars) to the classpath of the server to make the method available on the server side.

ObjectDB Support

Reply