有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java是由:org引起的。冬眠MappingException:无法确定的类型

我有一个JPA Entityas

@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
}

当我试图在test中保存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)]

到底是什么问题?我怎样才能修好它


共 (1) 个答案

  1. # 1 楼答案

    您必须使用自己的表将版本设置为完整实体,就像使用Market一样,或者如果您想将其保存为Market的一部分,则应使用@Embeddeble注释使其可嵌入

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