Item实体已扩展到另一个具有Vmp属性的Entity Amp。如何在Jpql中查询Vmp。我可以在Jpql中进行投射吗?
我使用Jpql时没有这样的转换。
select i from Stock i where i.stock >:s and i.department=:d and i.itemBatch.item.vmp=:vmp order by i.itemBatch.item.name
ItemBatch具有Item类的属性,但是我仅收回Amp实体,该实体扩展了Item类。只有Amp具有Vmp的属性。因此,上面的Jpql给出了以下错误。
Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Problem compiling [select i from Stock i where i.stock >:s and i.department=:d and i.itemBatch.item.vmp=:vmp order by i.itemBatch.item.name].
[85, 105] The state field path 'i.itemBatch.item.vmp' cannot be resolved to a valid type.
我可以像下面一样在Jpql中进行转换吗,还有其他解决方法吗?
select i from Stock i where i.stock >:s and i.department=:d and Atm(i.itemBatch.item).vmp=:vmp order by i.itemBatch.item.name
最佳答案
我找到了方法,必须使用对待而不是强制转换。这是Jpql
jpql = "select i from Stock i join treat(i.itemBatch.item as Amp) amp where i.stock >:s and i.department=:d and amp.vmp=:vmp order by i.itemBatch.item.name";