org.hibernate.MappingException 尽管 JPA 转换器可用
org.hibernate.MappingException despite JPA Converter is available
我有自己的 Id 类型
public class Id<T extends AbstractEntity<T>> {}
和一个 JPA 属性转换器:
@Converter(autoApply = true)
public class IdConverter<T extends Entity<T>> implements AttributeConverter<Id, Long> {
//...
}
尽管我在 属性 中使用了 @Converter(autoApply = true)
和 @Convert(...)
,但当我使用 Hibernate 4.3.7 启动我的应用程序时,我遇到了映射异常:
org.hibernate.MappingException: Could not determine type for: com.bosch.si.acm.persistence.domain.Id, at table: ACM007_CATEGORY, for columns: [org.hibernate.mapping.Column(id)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:271) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:852) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
... 100 common frames omitted
对于以下数据模型:
@Entity
@Table(name = "CATEGORY")
public class Category extends AbstractEntity<Category> {
//...
}
public class AbstractEntity<T extends AbstractEntity<T>> implements Entity<T> {
private static final long serialVersionUID = -2320097975522208226L;
@javax.persistence.Id
@GeneratedValue(generator = "id-generator")
@GenericGenerator(
name = "id-generator",
strategy = "com.....IdGenerator",
parameters = {
@Parameter(name = "sequence", value = "STANDARD_SEQ")
})
@Convert(converter = IdConverter.class, attributeName = "id")
@Column(columnDefinition = "NUMBER")
private Id<T> id = Id.newId();
}
我相信,这是因为您的转换器 class 使用了泛型。尝试删除 <T extends Entity<T>>
部分。
我有自己的 Id 类型
public class Id<T extends AbstractEntity<T>> {}
和一个 JPA 属性转换器:
@Converter(autoApply = true)
public class IdConverter<T extends Entity<T>> implements AttributeConverter<Id, Long> {
//...
}
尽管我在 属性 中使用了 @Converter(autoApply = true)
和 @Convert(...)
,但当我使用 Hibernate 4.3.7 启动我的应用程序时,我遇到了映射异常:
org.hibernate.MappingException: Could not determine type for: com.bosch.si.acm.persistence.domain.Id, at table: ACM007_CATEGORY, for columns: [org.hibernate.mapping.Column(id)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.mapping.RootClass.validate(RootClass.java:271) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.validate(Configuration.java:1360) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1851) ~[hibernate-core-4.3.7.Final.jar:4.3.7.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.perform(EntityManagerFactoryBuilderImpl.java:852) ~[hibernate-entitymanager-4.3.7.Final.jar:4.3.7.Final]
... 100 common frames omitted
对于以下数据模型:
@Entity
@Table(name = "CATEGORY")
public class Category extends AbstractEntity<Category> {
//...
}
public class AbstractEntity<T extends AbstractEntity<T>> implements Entity<T> {
private static final long serialVersionUID = -2320097975522208226L;
@javax.persistence.Id
@GeneratedValue(generator = "id-generator")
@GenericGenerator(
name = "id-generator",
strategy = "com.....IdGenerator",
parameters = {
@Parameter(name = "sequence", value = "STANDARD_SEQ")
})
@Convert(converter = IdConverter.class, attributeName = "id")
@Column(columnDefinition = "NUMBER")
private Id<T> id = Id.newId();
}
我相信,这是因为您的转换器 class 使用了泛型。尝试删除 <T extends Entity<T>>
部分。