简体   繁体   English

原因:org.hibernate.MappingException:无法确定类型

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

I have a JPA Entity as 我有一个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

Which contains a Version and Version class looks like 其中包含一个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
}

When I try to save the market entity in test, 当我尝试保存测试中的market实体时,

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

I see error 我看到错误

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)]

What exactly is the issue here? 这到底是什么问题? How can I fix it? 我该如何解决?

You either have to make Version a full entity with it's own table like you did with Market or if you want to save it as a part of Market you should make it embeddable using the @Embeddable annotation. 您必须像对待Market一样,使Version带有其自己的表成为完整实体,或者如果要将其保存为Market的一部分,则应使用@Embeddable注释使其可嵌入。

If you make it embeddable then you will have to remove the @Column annotation from the marketVersion field in Market. 如果使其可嵌入,则必须从Market的marketVersion字段中删除@Column批注。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 引起:org.hibernate.MappingException:无法确定类型: - Caused by: org.hibernate.MappingException: Could not determine type for: org.hibernate.MappingException:无法确定以下类型: - org.hibernate.MappingException: Could not determine type for: org.hibernate.MappingException:无法确定类型 - org.hibernate.MappingException: Could not determine type org.hibernate.MappingException:无法确定以下类型: - org.hibernate.MappingException: Could not determine type for: org.hibernate.MappingException:无法确定类型 - org.hibernate.MappingException: Could not determine type for 引起:org.hibernate.MappingException:无法确定类型:时间戳,列:[org.hibernate.mapping.Column(***)] - Caused by: org.hibernate.MappingException: Could not determine type for: Timestamp, for columns: [org.hibernate.mapping.Column(***)] 一对一的休眠原因:org.hibernate.MappingException:无法确定其类型 - Hibernate One To One Caused by: org.hibernate.MappingException: Could not determine type for Hibernate ORM失败:org.hibernate.MappingException:无法确定类型: - Hibernate ORM Failed:org.hibernate.MappingException: Could not determine type for: org.hibernate.MappingException:无法确定自定义 object 类型的类型 - org.hibernate.MappingException: Could not determine type for custom object type Spring 启动错误 org.hibernate.MappingException:无法确定类型 - Spring boot error org.hibernate.MappingException: Could not determine type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM