无法将@NamedEntityGraph 与@ElementCollecion 一起使用
Unable to use @NamedEntityGraph with @ElementCollecion
我正在尝试设置带有 NamedEntityGraph 的简单实体。不幸的是它不会工作。您能知道如何修复它吗?
ServiceType 实体具有 @ElementCollection
个 Set
个 String
个,它们只是与实体关联的 PictureModel
个 ID。在 运行 我得到了:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [backgroundPicIds] on this ManagedType [pl.mihome.djcost.model.ServiceType]
@Entity
@Table(name = "service_type")
@Getter
@Setter
@NoArgsConstructor
@NamedEntityGraph(
name = "serviceType.with.backgroundPicIds",
attributeNodes = @NamedAttributeNode("backgroundPicIds")
)
public class ServiceType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Setter(AccessLevel.NONE)
@Column(nullable = false, updatable = false)
private int id;
@Length(max = 100)
@NotBlank
private String name;
private boolean active;
@OneToMany(mappedBy = "serviceType")
private Set<Account> accounts;
@ManyToMany(mappedBy = "servicesApplicable")
private Set<AccountType> accountTypes;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "serviceType", orphanRemoval = true, cascade = CascadeType.ALL)
private Set<PictureModel> backgroundPicture;
@ElementCollection
@CollectionTable(name = "image", joinColumns = {@JoinColumn(name = "service_type_id")})
@Column(name = "id")
private Set<String> backgroundPictureId;
@PrePersist
void activate() {
this.active = true;
}
}
@Entity
@Table(name = "image")
@NoArgsConstructor
@Getter
@Setter
@Builder
@AllArgsConstructor
public class PictureModel {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(nullable = false, updatable = false)
@Setter(AccessLevel.NONE)
private String id;
private String type;
private String name;
@Lob
private byte[] body;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "public_platform_id")
private PublicPlatform publicPlatform;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "service_type_id")
private ServiceType serviceType;
}
您只是在实体 ServiceType
中没有名称为 backgroundPicIds
的属性。
尝试以这种方式更正您的图表:
@NamedEntityGraph(
name = "serviceType.with.backgroundPicIds",
attributeNodes = @NamedAttributeNode("backgroundPictureId")
)
我正在尝试设置带有 NamedEntityGraph 的简单实体。不幸的是它不会工作。您能知道如何修复它吗?
ServiceType 实体具有 @ElementCollection
个 Set
个 String
个,它们只是与实体关联的 PictureModel
个 ID。在 运行 我得到了:
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [backgroundPicIds] on this ManagedType [pl.mihome.djcost.model.ServiceType]
@Entity
@Table(name = "service_type")
@Getter
@Setter
@NoArgsConstructor
@NamedEntityGraph(
name = "serviceType.with.backgroundPicIds",
attributeNodes = @NamedAttributeNode("backgroundPicIds")
)
public class ServiceType {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Setter(AccessLevel.NONE)
@Column(nullable = false, updatable = false)
private int id;
@Length(max = 100)
@NotBlank
private String name;
private boolean active;
@OneToMany(mappedBy = "serviceType")
private Set<Account> accounts;
@ManyToMany(mappedBy = "servicesApplicable")
private Set<AccountType> accountTypes;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "serviceType", orphanRemoval = true, cascade = CascadeType.ALL)
private Set<PictureModel> backgroundPicture;
@ElementCollection
@CollectionTable(name = "image", joinColumns = {@JoinColumn(name = "service_type_id")})
@Column(name = "id")
private Set<String> backgroundPictureId;
@PrePersist
void activate() {
this.active = true;
}
}
@Entity
@Table(name = "image")
@NoArgsConstructor
@Getter
@Setter
@Builder
@AllArgsConstructor
public class PictureModel {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(nullable = false, updatable = false)
@Setter(AccessLevel.NONE)
private String id;
private String type;
private String name;
@Lob
private byte[] body;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "account_id")
private Account account;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "public_platform_id")
private PublicPlatform publicPlatform;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "service_type_id")
private ServiceType serviceType;
}
您只是在实体 ServiceType
中没有名称为 backgroundPicIds
的属性。
尝试以这种方式更正您的图表:
@NamedEntityGraph(
name = "serviceType.with.backgroundPicIds",
attributeNodes = @NamedAttributeNode("backgroundPictureId")
)