内部带有集合的实体视图不使用 Blaze 持久性
Entity view with a collection inside not working with Blaze persistance
我对使用 blaze 持久性库的实体视图有疑问。我想检索供应商列表,每个供应商都有一个产品列表,但我在创建实体视图模型时遇到异常。
设置
- Blaze 持久性核心 1.6.6
- Blaze 持久性实体视图 1.6.6
- Spring 数据 JPA 2.5.6
- 休眠 5.4.27
我正在使用显示的 Blaze 基本配置 here。
型号
这是我的模型(为了更清楚,我删除了一些字段):
@Entity(name = "suppliers")
public class Supplier extends BaseEntity {
@Column(nullable = false, length = 100)
private String businessName;
@OneToMany(mappedBy = "supplier")
private List<Product> products;
}
@Entity(name = "products")
public class Product extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private Integer price;
@ManyToOne
private Supplier supplier;
}
实体浏览量
@EntityView(Supplier.class)
public interface SupplierWithProductsView {
Integer getId();
String getBusinessName();
List<ProductView> getProducts();
}
@EntityView(Product.class)
public interface ProductView {
Integer getId();
String getName();
Integer getPrice();
}
例外情况
我在启动时遇到的异常如下:
Caused by: java.lang.IllegalArgumentException: Illegal occurence of [products] in path chain resolver!
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.invalid(PathTargetResolvingExpressionVisitor.java:562) ~[blaze-persistence-core-parser-1.6.6.jar:1.6.6]
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.visit(PathTargetResolvingExpressionVisitor.java:468) ~[blaze-persistence-core-parser-1.6.6.jar:1.6.6]
at com.blazebit.persistence.parser.expression.EntityLiteral.accept(EntityLiteral.java:50) ~[blaze-persistence-core-parser-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:125) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:120) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.AttributeMapping.determineIndexed(AttributeMapping.java:333) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.attribute.AbstractMethodListAttribute.<init>(AbstractMethodListAttribute.java:61) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.attribute.MappingMethodListAttribute.<init>(MappingMethodListAttribute.java:35) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MethodAttributeMapping.getMethodAttribute(MethodAttributeMapping.java:757) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImpl.<init>(ManagedViewTypeImpl.java:319) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.FlatViewTypeImpl.<init>(FlatViewTypeImpl.java:41) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.ViewMappingImpl.getManagedViewType(ViewMappingImpl.java:892) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContextImpl.getManagedViewType(MetamodelBuildingContextImpl.java:234) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.ViewMetamodelImpl.<init>(ViewMetamodelImpl.java:88) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:271) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
... 60 common frames omitted
我尝试通过调试和调查库代码来进行一些测试,我发现如果我将 @MappingIndex
添加到视图中的产品列表中,抛出的异常似乎更清楚。我还没有完全理解映射索引是如何工作的,但也许它是相关的。以下是新的异常:
Caused by: java.lang.IllegalArgumentException: There are error(s) in entity views!
The resolved possible types [java.util.List] are not assignable to the given expression type 'java.util.Collection<my.package.Product>' of the mapping expression declared by the attribute products[my.package.SupplierWithProductsView.getProducts]!
at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:285) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.EntityViewConfigurationImpl.createEntityViewManager(EntityViewConfigurationImpl.java:206) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at my.package.configurations.BlazePersistenceConfig.createEntityViewManager(BlazePersistenceConfig.java:44) ~[main/:na]
... other lines omitted
有人知道如何解决我的问题吗?
提前致谢!
我现在测试了您的示例应用程序,我看到了这个异常:
Caused by: java.lang.IllegalArgumentException: Illegal occurence of [products] in path chain resolver!
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.invalid(PathTargetResolvingExpressionVisitor.java:562)
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.visit(PathTargetResolvingExpressionVisitor.java:468)
at com.blazebit.persistence.parser.expression.EntityLiteral.accept(EntityLiteral.java:50)
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:125)
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:120)
at com.blazebit.persistence.view.impl.metamodel.AttributeMapping.determineIndexed(AttributeMapping.java:333)
at com.blazebit.persistence.view.impl.metamodel.attribute.AbstractMethodListAttribute.<init>(AbstractMethodListAttribute.java:61)
at com.blazebit.persistence.view.impl.metamodel.attribute.MappingMethodListAttribute.<init>(MappingMethodListAttribute.java:35)
at com.blazebit.persistence.view.impl.metamodel.MethodAttributeMapping.getMethodAttribute(MethodAttributeMapping.java:757)
at com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImpl.<init>(ManagedViewTypeImpl.java:319)
at com.blazebit.persistence.view.impl.metamodel.FlatViewTypeImpl.<init>(FlatViewTypeImpl.java:41)
at com.blazebit.persistence.view.impl.metamodel.ViewMappingImpl.getManagedViewType(ViewMappingImpl.java:892)
at com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContextImpl.getManagedViewType(MetamodelBuildingContextImpl.java:234)
at com.blazebit.persistence.view.impl.metamodel.ViewMetamodelImpl.<init>(ViewMetamodelImpl.java:88)
at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:271)
错误意味着在幕后为 SupplierWithProductsView#getProducts
创建的表达式 products
是非法的。这是关联被命名为与实体 ProductEntity
相同的不幸副作用,即 @Entity(name = "products")
。我为此创建了以下错误报告,并将尽快对此进行调查:https://github.com/Blazebit/blaze-persistence/issues/1450
同时,您可以将关联重命名为例如productList
、seelingProducts
或类似的东西。或者,您也可以使用 @Entity(name = "product")
重命名实体,即省略 s
.
我对使用 blaze 持久性库的实体视图有疑问。我想检索供应商列表,每个供应商都有一个产品列表,但我在创建实体视图模型时遇到异常。
设置
- Blaze 持久性核心 1.6.6
- Blaze 持久性实体视图 1.6.6
- Spring 数据 JPA 2.5.6
- 休眠 5.4.27
我正在使用显示的 Blaze 基本配置 here。
型号
这是我的模型(为了更清楚,我删除了一些字段):
@Entity(name = "suppliers")
public class Supplier extends BaseEntity {
@Column(nullable = false, length = 100)
private String businessName;
@OneToMany(mappedBy = "supplier")
private List<Product> products;
}
@Entity(name = "products")
public class Product extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private Integer price;
@ManyToOne
private Supplier supplier;
}
实体浏览量
@EntityView(Supplier.class)
public interface SupplierWithProductsView {
Integer getId();
String getBusinessName();
List<ProductView> getProducts();
}
@EntityView(Product.class)
public interface ProductView {
Integer getId();
String getName();
Integer getPrice();
}
例外情况
我在启动时遇到的异常如下:
Caused by: java.lang.IllegalArgumentException: Illegal occurence of [products] in path chain resolver!
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.invalid(PathTargetResolvingExpressionVisitor.java:562) ~[blaze-persistence-core-parser-1.6.6.jar:1.6.6]
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.visit(PathTargetResolvingExpressionVisitor.java:468) ~[blaze-persistence-core-parser-1.6.6.jar:1.6.6]
at com.blazebit.persistence.parser.expression.EntityLiteral.accept(EntityLiteral.java:50) ~[blaze-persistence-core-parser-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:125) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:120) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.AttributeMapping.determineIndexed(AttributeMapping.java:333) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.attribute.AbstractMethodListAttribute.<init>(AbstractMethodListAttribute.java:61) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.attribute.MappingMethodListAttribute.<init>(MappingMethodListAttribute.java:35) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MethodAttributeMapping.getMethodAttribute(MethodAttributeMapping.java:757) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImpl.<init>(ManagedViewTypeImpl.java:319) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.FlatViewTypeImpl.<init>(FlatViewTypeImpl.java:41) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.ViewMappingImpl.getManagedViewType(ViewMappingImpl.java:892) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContextImpl.getManagedViewType(MetamodelBuildingContextImpl.java:234) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.metamodel.ViewMetamodelImpl.<init>(ViewMetamodelImpl.java:88) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:271) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
... 60 common frames omitted
我尝试通过调试和调查库代码来进行一些测试,我发现如果我将 @MappingIndex
添加到视图中的产品列表中,抛出的异常似乎更清楚。我还没有完全理解映射索引是如何工作的,但也许它是相关的。以下是新的异常:
Caused by: java.lang.IllegalArgumentException: There are error(s) in entity views!
The resolved possible types [java.util.List] are not assignable to the given expression type 'java.util.Collection<my.package.Product>' of the mapping expression declared by the attribute products[my.package.SupplierWithProductsView.getProducts]!
at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:285) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at com.blazebit.persistence.view.impl.EntityViewConfigurationImpl.createEntityViewManager(EntityViewConfigurationImpl.java:206) ~[blaze-persistence-entity-view-impl-1.6.6.jar:1.6.6]
at my.package.configurations.BlazePersistenceConfig.createEntityViewManager(BlazePersistenceConfig.java:44) ~[main/:na]
... other lines omitted
有人知道如何解决我的问题吗?
提前致谢!
我现在测试了您的示例应用程序,我看到了这个异常:
Caused by: java.lang.IllegalArgumentException: Illegal occurence of [products] in path chain resolver!
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.invalid(PathTargetResolvingExpressionVisitor.java:562)
at com.blazebit.persistence.parser.PathTargetResolvingExpressionVisitor.visit(PathTargetResolvingExpressionVisitor.java:468)
at com.blazebit.persistence.parser.expression.EntityLiteral.accept(EntityLiteral.java:50)
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:125)
at com.blazebit.persistence.view.impl.metamodel.MetamodelUtils.isIndexedList(MetamodelUtils.java:120)
at com.blazebit.persistence.view.impl.metamodel.AttributeMapping.determineIndexed(AttributeMapping.java:333)
at com.blazebit.persistence.view.impl.metamodel.attribute.AbstractMethodListAttribute.<init>(AbstractMethodListAttribute.java:61)
at com.blazebit.persistence.view.impl.metamodel.attribute.MappingMethodListAttribute.<init>(MappingMethodListAttribute.java:35)
at com.blazebit.persistence.view.impl.metamodel.MethodAttributeMapping.getMethodAttribute(MethodAttributeMapping.java:757)
at com.blazebit.persistence.view.impl.metamodel.ManagedViewTypeImpl.<init>(ManagedViewTypeImpl.java:319)
at com.blazebit.persistence.view.impl.metamodel.FlatViewTypeImpl.<init>(FlatViewTypeImpl.java:41)
at com.blazebit.persistence.view.impl.metamodel.ViewMappingImpl.getManagedViewType(ViewMappingImpl.java:892)
at com.blazebit.persistence.view.impl.metamodel.MetamodelBuildingContextImpl.getManagedViewType(MetamodelBuildingContextImpl.java:234)
at com.blazebit.persistence.view.impl.metamodel.ViewMetamodelImpl.<init>(ViewMetamodelImpl.java:88)
at com.blazebit.persistence.view.impl.EntityViewManagerImpl.<init>(EntityViewManagerImpl.java:271)
错误意味着在幕后为 SupplierWithProductsView#getProducts
创建的表达式 products
是非法的。这是关联被命名为与实体 ProductEntity
相同的不幸副作用,即 @Entity(name = "products")
。我为此创建了以下错误报告,并将尽快对此进行调查:https://github.com/Blazebit/blaze-persistence/issues/1450
同时,您可以将关联重命名为例如productList
、seelingProducts
或类似的东西。或者,您也可以使用 @Entity(name = "product")
重命名实体,即省略 s
.