簡體   English   中英

原因:org.hibernate.MappingException:無法確定類型

[英]Caused by: org.hibernate.MappingException: Could not determine type for

我有一個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)]

這到底是什么問題? 我該如何解決?

您必須像對待Market一樣,使Version帶有其自己的表成為完整實體,或者如果要將其保存為Market的一部分,則應使用@Embeddable注釋使其可嵌入。

如果使其可嵌入,則必須從Market的marketVersion字段中刪除@Column批注。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM