Spring data jpa spring数据@ManyToOne@MapsId
有人能帮我正确地映射这3个实体吗,因为我已经尝试了许多解决方案,但都不起作用。 我有3个实体: 应按以下方式映射的产品、项目和包装: 产品实体 项目实体Spring data jpa spring数据@ManyToOne@MapsId,spring-data-jpa,mapping,Spring Data Jpa,Mapping,有人能帮我正确地映射这3个实体吗,因为我已经尝试了许多解决方案,但都不起作用。 我有3个实体: 应按以下方式映射的产品、项目和包装: 产品实体 项目实体 Remove@primarykeyjoincolumn我已经尝试过了,但不起作用。在OneToMany映射包列表中,有一个mappedBy=“item”丢失。您找到答案了吗??但EclipseLink 2.7.7仍然存在这个问题。。 public class Product implements Serializable { @OneT
Remove@primarykeyjoincolumn我已经尝试过了,但不起作用。在OneToMany映射包列表中,有一个mappedBy=“item”丢失。您找到答案了吗??但EclipseLink 2.7.7仍然存在这个问题。。
public class Product implements Serializable {
@OneToMany(mappedBy="parentProduct", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@PrimaryKeyJoinColumn
private List<Pack> packListParent;
@OneToMany(mappedBy="childProduct", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@PrimaryKeyJoinColumn
private List<Pack> packListChild;
}
public class Pack implements Serializable {
@EmbeddedId
protected PackPK PackPK;
@MapsId("itemId")
@JoinColumn(name = "item_id", referencedColumnName = "item_id", insertable = true, updatable = true)
@ManyToOne(fetch = FetchType.LAZY)
private Item item;
@MapsId("parentProductId")
@JoinColumn(name = "product_id", referencedColumnName = "product_id", insertable = true, updatable = true)
@ManyToOne(fetch = FetchType.LAZY)
private Product parentProduct;
@MapsId("childProductId")
@JoinColumn(name = "child_product_id", referencedColumnName = "product_id", insertable = true, updatable = true)
@ManyToOne(fetch = FetchType.LAZY)
private Product childProduct;
}
@Embeddable
public class PackPK implements Serializable {
@Basic(optional = false)
@Column(name = "product_id")
private Long parentProductId;
@Basic(optional = false)
@Column(name = "item_id")
private Long itemId;
@Basic(optional = false)
@Column(name = "child_product_id")
private Long childProductId;
}
public class Item implements Serializable {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true)
@PrimaryKeyJoinColumn
private List<Pack> PackList;
}
WARN - [AnnotationConfigServletWebServerApplicationContext]
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'produitService': Unsatisfied dependency expressed through field 'PackService';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'PackService': Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException: Expected id attribute type [class com.project.jpa.domain.PackPK]
on the existing id attribute [SingularAttributeImpl[EntityTypeImpl@1851998201:Item
[ javaType: class com.project.jpa.domain.Item descriptor: RelationalDescriptor(com.project.jpa.domain.Item --> [DatabaseTable(item)]), mappings: 47],
org.eclipse.persistence.mappings.ManyToOneMapping[item]]] on the identifiable type [EntityTypeImpl@1341697553:Pack [ javaType: class com.project.jpa.domain.Pack descriptor:
RelationalDescriptor(com.project.jpa.domain.Pack --> [DatabaseTable(pack_svod_content)]), mappings: 6]] but found attribute type [class com.project.jpa.domain.Item].