2

我有JPA Entity一个

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = { "name", "market_version" }))
public class Market extends MutableEntity {

    @Column(nullable = false)
    private String name;
    @Column
    private String description;
    @Column(name = "market_version", nullable = false)
    private Version marketVersion;

    public Market(final String name, final String description) {
        this.name = name;
        this.description = description;
        this.marketVersion = new Version("1.0", VersionType.MAJOR, VersionStatus.ACTIVE);
    } ... snipped

其中包含一个VersionVersion类看起来像

public class Version {
    private String name;
    private VersionType type;
    private VersionStatus status;
    private DateTime publishedOn;
    private DateTime retiredOn;
    private Version parentVersion;

    public Version(@Nonnull final String name, @Nonnull final VersionType type, @Nonnull final VersionStatus status) {
        this.name = name;
        this.type = type;
        this.status = status;
    }
}

enum VersionType {
    MAJOR,
    MINOR,
    BOTH
}

enum VersionStatus {
    ACTIVE,
    RETIRED
}

当我尝试market在测试中保存实体时,

    @Test
    public void testMarket() {
        final Market market = new Market("test", "test market");
        final MarketCrudService crudService = new MarketCrudService(jpaRule.getEntityManager());
        crudService.create(market);
    }

我看到错误

Caused by: org.hibernate.MappingException: Could not determine type for: com.myorg.project.versioning.entities.Version, at table: Market, for columns: [org.hibernate.mapping.Column(market_version)]

这里的问题到底是什么?我该如何解决?

4

1 回答 1

0

您要么必须像使用 Market 一样使用它自己的表使 Version 成为一个完整的实体,要么如果您想将其保存为 Market 的一部分,您应该使用 @Embeddable 注释使其可嵌入。

如果将其设为可嵌入的,则必须从 Market 的 marketVersion 字段中删除 @Column 注释。

于 2013-02-10T07:05:28.327 回答