EclipseLink JPA NamedQuery 在 Set 类型的字段中找不到 .size 属性
EclipseLink JPA NamedQuery can not find .size Attribute in field of type Set
我正在使用 EclipseLink 将一些数据库方法从 Hibernate 迁移到 JPA,并且有一个 NamedQuery 有问题,它使用 Set 中的 .size 方法对结果进行排序。
这是我的实体 class,其中包含导致问题的查询和字段:
@Entity
@Table(name = "PRODUCT")
@DiscriminatorValue(value = "Bundle")
@NamedQueries({@NamedQuery(name = BundleProduct.findProductBundles, query = "select distinct bundle from BundleProduct bundle inner join bundle.products as product inner join bundle.services as service where service.name = :service and product in (:products) and not exists (select product2 from BundleProduct bundle2 join bundle2.products as product2 where bundle = bundle2 and product2 not in (:products)) order by product.size desc, bundle.name")})
public class BundleProduct extends Product
{
@ManyToMany
@JoinTable(name = "SERVICEPRODUCT",
joinColumns = {@JoinColumn(name = "ITSPRODUCT")},
inverseJoinColumns = {@JoinColumn(name = "ITSSERVICE")})
private Set<SingleProduct> products;
这会导致我的应用程序服务器 (Weblogic 12.2.1.0.0) 发生异常:
Exception Description: Deployment of PersistenceUnit [myunit] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select distinct bundle from BundleProduct bundle join bundle.products as product join bundle.services as service where service.name = :service and product in (:products) and not exists (select product2 from BundleProduct bundle2 join bundle2.products as product2 where bundle = bundle2 and product2 not in (:products)) order by product.size desc, bundle.name]. [349, 361] The state field path 'product.size' cannot be resolved to a valid type.
"order by" 子句的第一部分曾经是 "bundle.products.size",我的印象是将其更改为 "product.size" 应该可以解决问题,但我仍然遇到异常。
在我研究这个问题的过程中,我发现多篇文章都说 IDE 似乎可以自动完成这些查询,但后来就不起作用了。我正在使用 IDEA 14.1.5.
The state field path 'product.size' cannot be resolved to a valid
type.
是的 "size" 不存在,但是 JPQL 有 SIZE(...) 来处理这个。
ORDER BY SIZE(products) DESC, bundle.name
一如既往,请参阅 JPQL 参考文档以查看可用的功能,例如 this one。
我正在使用 EclipseLink 将一些数据库方法从 Hibernate 迁移到 JPA,并且有一个 NamedQuery 有问题,它使用 Set 中的 .size 方法对结果进行排序。 这是我的实体 class,其中包含导致问题的查询和字段:
@Entity
@Table(name = "PRODUCT")
@DiscriminatorValue(value = "Bundle")
@NamedQueries({@NamedQuery(name = BundleProduct.findProductBundles, query = "select distinct bundle from BundleProduct bundle inner join bundle.products as product inner join bundle.services as service where service.name = :service and product in (:products) and not exists (select product2 from BundleProduct bundle2 join bundle2.products as product2 where bundle = bundle2 and product2 not in (:products)) order by product.size desc, bundle.name")})
public class BundleProduct extends Product
{
@ManyToMany
@JoinTable(name = "SERVICEPRODUCT",
joinColumns = {@JoinColumn(name = "ITSPRODUCT")},
inverseJoinColumns = {@JoinColumn(name = "ITSSERVICE")})
private Set<SingleProduct> products;
这会导致我的应用程序服务器 (Weblogic 12.2.1.0.0) 发生异常:
Exception Description: Deployment of PersistenceUnit [myunit] failed. Close all factories for this PersistenceUnit.
Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select distinct bundle from BundleProduct bundle join bundle.products as product join bundle.services as service where service.name = :service and product in (:products) and not exists (select product2 from BundleProduct bundle2 join bundle2.products as product2 where bundle = bundle2 and product2 not in (:products)) order by product.size desc, bundle.name]. [349, 361] The state field path 'product.size' cannot be resolved to a valid type.
"order by" 子句的第一部分曾经是 "bundle.products.size",我的印象是将其更改为 "product.size" 应该可以解决问题,但我仍然遇到异常。
在我研究这个问题的过程中,我发现多篇文章都说 IDE 似乎可以自动完成这些查询,但后来就不起作用了。我正在使用 IDEA 14.1.5.
The state field path 'product.size' cannot be resolved to a valid type.
是的 "size" 不存在,但是 JPQL 有 SIZE(...) 来处理这个。
ORDER BY SIZE(products) DESC, bundle.name
一如既往,请参阅 JPQL 参考文档以查看可用的功能,例如 this one。