当我执行以下查询时:
return (Formation) em
.createQuery(
"SELECT f FROM Formation f WHERE f.model" + modelType + "= :modelId")
.setParameter("modelId", modelId)
.getSingleResult();
我收到此错误:
org.hibernate.PropertyAccessException:无法通过model.configuration.Model.id的反射getter获取字段值
当我用如上所述的丑陋查询替换预准备语句时,它可以工作:
return (Formation) em
.createQuery(
"SELECT f FROM Formation f WHERE f.model" + modelType + "= " + modelId)
.getSingleResult();
答案 0 :(得分:0)
我猜modelId
是嵌套实体的id而不是实体本身因此我会期待这样的事情
"SELECT f FROM Formation f WHERE f.model" + modelType + ".ModelId = :modelId")