0

我正在尝试在其上设置带有 NamedEntityGraph 的简单实体。不幸的是,它不起作用。你能知道如何解决它吗?

ServiceType 实体具有@ElementCollection的只是与实体关联的SetID 。运行时我得到:StringPictureModel

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;
}
4

1 回答 1

0

您根本没有backgroundPicIds实体中具有名称的属性ServiceType

尝试以这种方式更正您的图表:

@NamedEntityGraph(
   name = "serviceType.with.backgroundPicIds",
   attributeNodes = @NamedAttributeNode("backgroundPictureId")
)
于 2020-11-13T11:39:17.813 回答