Search code examples
hibernatejpajpa-2.1

org.hibernate.MappingException despite JPA Converter is available


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();
}

Solution

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