org.hibernate.MappingException 尽管 JPA 转换器可用
Posted
技术标签:
【中文标题】org.hibernate.MappingException 尽管 JPA 转换器可用【英文标题】:org.hibernate.MappingException despite JPA Converter is available 【发布时间】:2015-02-02 15:17:23 【问题描述】:我有自己的 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();
【问题讨论】:
【参考方案1】:我相信,这是因为您的转换器类使用了泛型。尝试删除 <T extends Entity<T>>
部分。
【讨论】:
以上是关于org.hibernate.MappingException 尽管 JPA 转换器可用的主要内容,如果未能解决你的问题,请参考以下文章