[英]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 其中包含一个Version
和Version
类看起来像
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.