org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)]

Hibernate JIRA | Marcelo Glasberg | 3 years ago
  1. 0

    Hibernate Envers fails with @Converter and AttributeConverter (JPA 2.1)

    Stack Overflow | 3 years ago | MarcG
    org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)]
  2. 0

    Without a JPA 2.1 Converter, the Party entity below fails at Configuration.buildSessionFactory() as it should, since Hibernate doesn't know what to do with the Name class: {code} @Entity @Audited public class Party { protected Name name; ... } {code} The exception is: {code} org.hibernate.MappingException: Could not determine type for: ModuloADM.Party.Name, at table: Party, for columns: [org.hibernate.mapping.Column(name)] {code} To fix this, I then add this converter: {code} @Converter (autoApply=true) public class NametoStringConverter implements AttributeConverter<Name, String> { ... } {code} And the exception now changes to: {code} org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)] {code} This is now failing at the Envers auditing table for the Party entity. Note that History_Party is the name of the audit table, as choosen by config.setProperty("org.hibernate.envers.audit_table_prefix", "History_"). The complete stacktrace is: {code} org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) at org.hibernate.tuple.PropertyFactory.buildEntityBasedAttribute(PropertyFactory.java:246) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:227) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148) at sun.reflect.GeneratedConstructorAccessor43.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) {code}

    Hibernate JIRA | 3 years ago | Marcelo Glasberg
    org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)]
  3. 0

    Without a JPA 2.1 Converter, the Party entity below fails at Configuration.buildSessionFactory() as it should, since Hibernate doesn't know what to do with the Name class: {code} @Entity @Audited public class Party { protected Name name; ... } {code} The exception is: {code} org.hibernate.MappingException: Could not determine type for: ModuloADM.Party.Name, at table: Party, for columns: [org.hibernate.mapping.Column(name)] {code} To fix this, I then add this converter: {code} @Converter (autoApply=true) public class NametoStringConverter implements AttributeConverter<Name, String> { ... } {code} And the exception now changes to: {code} org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)] {code} This is now failing at the Envers auditing table for the Party entity. Note that History_Party is the name of the audit table, as choosen by config.setProperty("org.hibernate.envers.audit_table_prefix", "History_"). The complete stacktrace is: {code} org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) at org.hibernate.tuple.PropertyFactory.buildEntityBasedAttribute(PropertyFactory.java:246) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:227) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148) at sun.reflect.GeneratedConstructorAccessor43.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) {code}

    Hibernate JIRA | 3 years ago | Marcelo Glasberg
    org.hibernate.MappingException: Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)]
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    I have 2 entities: User and UserGroup (omitting some code to shorten here..): {code:java} @Entity @Table(name = "`User`") // using backtick since User is a reserved word in SqlServer 2012 public class User implements java.io.Serializable { [...] private UserGroup userGroup; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "userGroupId", insertable = false) @Generated(GenerationTime.INSERT) public UserGroup getUserGroup() { return this.userGroup; } [...] // omitting setter for userGroup and other stuffs } {code} {code:java} @Entity @Table(name = "UserGroup") public class UserGroup implements java.io.Serializable { private int id; private String name; [...] // omitting code for simplicity here.. } {code} The userGroup property is generated at row insertion with a database trigger (this is not my real application but just to render the concept..), so I used @org.hibernate.annotations.Generated(GenerationTime.INSERT) to refresh the entity after a persist(). This behaviour worked fine in Hibernate 3.6.10. Migrating to 4.3.10 or 5.0.0.CR1 does not work anymore, giving this exception: {code:java} javax.persistence.PersistenceException: [PersistenceUnit: TestPU] Unable to build Hibernate SessionFactory at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39) at testH4.TestH4.main(TestH4.java:10) Caused by: org.hibernate.MappingException: Unknown entity: testH4.entities.UserGroup at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096) at org.hibernate.internal.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:1193) at org.hibernate.type.EntityType.getIdentifierType(EntityType.java:635) at org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:672) at org.hibernate.type.ManyToOneType.getColumnSpan(ManyToOneType.java:142) at org.hibernate.tuple.entity.EntityMetamodel.create(EntityMetamodel.java:459) at org.hibernate.tuple.entity.EntityMetamodel.buildGenerationStrategyPair(EntityMetamodel.java:424) at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:266) at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520) at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163) at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857) ... 8 more {code} At first glance, it seems the entity is not found by the factory, but removing the annotation @Generated from userGroup property, makes the sessionfactory building process working again. Investigating in core hibernate code, brought me to org.hibernate.tuple.entity.EntityMetamodel#create() at line 459 (hibernate 4.3.10, but 5.0.0.CR1 is similar). Here the EntityMetamodel tries to calculate the numberOfMappedColumns from the association: {code:java} public static InDatabaseValueGenerationStrategyImpl create( SessionFactoryImplementor sessionFactoryImplementor, Property mappingProperty, ValueGeneration valueGeneration) { final int numberOfMappedColumns = mappingProperty.getType().getColumnSpan( sessionFactoryImplementor ); // --- THIS IS LINE 459 --- if ( numberOfMappedColumns == 1 ) { return new InDatabaseValueGenerationStrategyImpl( valueGeneration.getGenerationTiming(), valueGeneration.referenceColumnInSql(), new String[] { valueGeneration.getDatabaseGeneratedReferencedColumnValue() } ); } else { [....] } {code} The problem here is that the metamodel tries to get the UserGroup entity persister, before it is actually created, and execution flow stops at SessionFactotyImpl:1096 (here the entityPersisters field is actually an empty map): {code:java} public EntityPersister getEntityPersister(String entityName) throws MappingException { EntityPersister result = entityPersisters.get(entityName); if ( result == null ) { throw new MappingException( "Unknown entity: " + entityName ); // LINE 1096 } return result; } {code} Removing the @Generated annotations makes the sessionfactory build ok. Another trick: changing EntityMetamodel, line 459 from: {code:java} final int numberOfMappedColumns = mappingProperty.getType().getColumnSpan( sessionFactoryImplementor ); {code} to {code:java} final int numberOfMappedColumns = 1; {code} makes the software work again, but I think this is not correct in all cases..

    Hibernate JIRA | 1 year ago | Luca Domenichini
    javax.persistence.PersistenceException: [PersistenceUnit: TestPU] Unable to build Hibernate SessionFactory
  6. 0

    Spring Envers fails with @Converter and AttributeConverter<LocalDate,Date>

    Stack Overflow | 6 months ago | Med
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring-config/db-mysql-context.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.MappingException

      Could not determine type for: BasicType adapter for AttributeConverter<Name,String>, at table: History_Party, for columns: [org.hibernate.mapping.Column(name)]

      at org.hibernate.mapping.SimpleValue.getType()
    2. Hibernate
      SingleTableEntityPersister.<init>
      1. org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)
      2. org.hibernate.tuple.PropertyFactory.buildEntityBasedAttribute(PropertyFactory.java:246)
      3. org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:227)
      4. org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
      5. org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)
      5 frames
    3. Java RT
      Constructor.newInstance
      1. sun.reflect.GeneratedConstructorAccessor43.newInstance(Unknown Source)
      2. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      3. java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      3 frames
    4. Hibernate
      Configuration.buildSessionFactory
      1. org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
      2. org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
      3. org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:401)
      4. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857)
      4 frames