尽管提供了JPA Converter,但仍存在org.hibernate.MappingException [英] org.hibernate.MappingException despite JPA Converter is available

查看:76
本文介绍了尽管提供了JPA Converter,但仍存在org.hibernate.MappingException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自己的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启动应用程序时却遇到了映射异常:

despite that I use @Converter(autoApply = true) and @Convert(...) at the property, I get a mapping exception when I start my application using 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();
}

推荐答案

我相信,这是因为您的转换器类使用泛型.尝试删除<T extends Entity<T>>部分.

I believe, it is because your converter class uses generics. Try removing the <T extends Entity<T>> part.

这篇关于尽管提供了JPA Converter,但仍存在org.hibernate.MappingException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆