具有两个参数的Java JPA查询
我正在使用Java和Spring框架,以及hibernate。我编写了一个接口,通过Querys获取一些库存信息,一个用于位置,一个用于产品类型:具有两个参数的Java JPA查询,java,spring,hibernate,jpa,Java,Spring,Hibernate,Jpa,我正在使用Java和Spring框架,以及hibernate。我编写了一个接口,通过Querys获取一些库存信息,一个用于位置,一个用于产品类型: public interface ProductInventory extends Inventory<InventoryItem> { @Query("select i from InventoryItem i, ProductItem c where i.product = c and c.type = ?1")
public interface ProductInventory extends Inventory<InventoryItem> {
@Query("select i from InventoryItem i, ProductItem c where i.product = c and c.type = ?1")
List<InventoryItem> findByProductType(ProductItem.ProductItem type);
@Query("select i from InventoryItem i, ProductItem c where i.product = c and c.locationid = ?1")
List<InventoryItem> findByProductLocation(long locationid);
}
公共接口ProductInventory扩展了库存{
@查询(“从InventoryItem i、ProductItem c中选择i,其中i.product=c和c.type=?1”)
列表findByProductType(ProductItem.ProductItem类型);
@查询(“从InventoryItem i、ProductItem c中选择i,其中i.product=c和c.locationid=?1”)
列出findByProductLocation(长位置ID);
}
这很好,但现在我想编写一个选择ProductType和位置的查询:
@Query("select i from InventoryItem i, ProductItem c where i.product = c and c.type = ?1 and c.locationid = ?1")
List<InventoryItem> findByProductStandortAndType(ProductItem.ProductItemType type, long locationid);
@Query(“从InventoryItem i、ProductItem c中选择i,其中i.product=c和c.type=?1和c.locationid=?1”)
列出findByProductStandortAndType(ProductItem.ProductItemType类型,长位置ID);
但这不起作用。也许有人能帮我?非常感谢那么为什么不在查询中使用第二个参数呢?第一个参数有两次“?1”