0

我的实体看起来像

@Entity

    @Table(uniqueConstraints = @UniqueConstraint(columnNames = {"id", "service_version_id"}))
    public class MarketVersion extends AbstractVersion<MarketVersion> {

        @ManyToOne(cascade = CascadeType.ALL)
        private Market market;

        @OneToOne
        private MarketVersion parentVersion;

        @OneToMany(cascade = CascadeType.MERGE)
        @JoinColumn(name = "services_id", referencedColumnName = "id")
        private List<ServiceVersion> services;
}

和服务看起来像

public class ServiceVersion extends AbstractVersion<ServiceVersion> {

    @ManyToOne(cascade = CascadeType.ALL)
    private Service service;
    @OneToOne
    private ServiceVersion parentVersion;
    @Column
    private String description;
    @Column(nullable = false)
    @Enumerated(EnumType.STRING)
    private ServiceImplementations implementation;
}

当我运行它时,我看到

[hibernatetool] javax.persistence.PersistenceException: [PersistenceUnit: market] Unable to configure EntityManagerFactory
[hibernatetool] org.hibernate.AnnotationException: Unable to create unique key constraint (id, service_version_id) on table MarketVersion: service_version_id not found

我肯定是新手,我做的不对,但无法理解,请指教

我想要一个对唯一(market_version_id 和 service_version_id)有约束的新表

4

1 回答 1

0

您的约束中的列被命名service_version_id,而您的实体中的连接列被命名为您在列上加入services_id。您需要service_version_id在数据库中创建列或将约束列重命名为services_id取决于您要实现的目标。

于 2013-03-06T20:31:16.157 回答