org.hibernate.MappingException despite JPA Converter is available

安稳与你 提交于 2019-12-11 02:27:55

问题


I've got a own Id type

public class Id<T extends AbstractEntity<T>> {}

and a JPA Attribute Converter:

@Converter(autoApply = true)
public class IdConverter<T extends Entity<T>> implements AttributeConverter<Id, Long> {
    //...
}

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

for the following datamodel:

@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:


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



来源:https://stackoverflow.com/questions/28280879/org-hibernate-mappingexception-despite-jpa-converter-is-available

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!