我有自己的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$4.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();
}
答案 0 :(得分:2)
我相信,这是因为您的转换器类使用泛型。请尝试删除<T extends Entity<T>>
部分。