java - 由 : org. 引起的 hibernate.MappingException: Could not determine type for

标签 java hibernate jakarta-ee jpa

我有一个 JPA 实体作为

@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 注释。

关于java - 由 : org. 引起的 hibernate.MappingException: Could not determine type for,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14795191/

相关文章:

java - 如何在github上发布java项目?

java - Spring Controller 预处理@ModelAttribute请求参数

java - 如何使用spring DAO保存外键实体

java - NoSuchBeanDefinitionException : No qualifying bean of type JpaVendorAdapter found for dependency

java - 如何在 Glassfish 中获取远程 EJB 客户端的 IP 地址?

java - java将所有数组元素重新初始化为零

java - Hibernate OneToMany 映射

java - 如何在 Spring Boot Hibernate Multi-Tenancy 应用程序中使用 C3P0 来管理连接池?

http - 如何使用 Java Servlet 实现像 BOSH 这样的东西

xml - 如何将 XML 文件用作数据库并通过 JAX-B API 访问它?