Hello everybody!
I just found a difference between using a list type as named parameter and using it as positional parameter and wonder if this is the expected behaviour.
Here the example:
Code:
List<TreeNode> children = this.node.getAllChildren();
JPA.em().createQuery("DELETE FROM Folder WHERE node IN (:children)")
.setParameter("children", children).executeUpdate();
In the example JPA.em() gives the current javax.persistence.EntityManager.
The code above works just as expected.
But when using the same parameter as positional parameter, i get an exception.
Code:
List<TreeNode> children = this.node.getAllChildren();
JPA.em().createQuery("DELETE FROM Folder WHERE node IN (?)")
.setParameter(1, children).executeUpdate();
Quote:
Caused by: javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of models.TreeNode.id
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1214)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1147)
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1224)
at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:108)
at models.FileSystemObject.delete(FileSystemObject.java:106)
at controllers.api.FileSystem.deleteFolderById(FileSystem.java:116)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:515)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:476)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:453)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:448)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:155)
... 1 more
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of models.TreeNode.id
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:227)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3850)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3558)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:203)
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:242)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:456)
at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:130)
at org.hibernate.param.PositionalParameterSpecification.bind(PositionalParameterSpecification.java:68)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:93)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:421)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:283)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1288)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:117)
at org.hibernate.ejb.QueryImpl.internalExecuteUpdate(QueryImpl.java:188)
at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:99)
... 8 more
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Long field models.TreeNode.id to java.util.ArrayList
at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59)
... 23 more
I only changed the parameter from a named parameter to a positional parameter.
Is this expected behaviour or a bug in Hibernate?
Thanks in advance!