org.hibernate.MappingException: Could not determine type for column idDependentObject of type org.hibernate.type.ManyToOneType: org.hibernate.MappingException

Hibernate JIRA | Vladimir Demochko | 1 decade ago
  1. 0

    Constructor of UnionsubclassEntityPersister initialize an objects loading SQL query in generateSubquery(PersistentClass) method. While construction of this SQL query method Column.getSqlTypeMethod(Mapping) is called (UnionsubclassEntityPersister.java:320) to determine NULL expression to be used. If column in question is a reference to an associated class (for example, an identifier for many-to-one relation), column will look for referenced entity primary key type. However, if the persister for referenced entity has not been yet created column type lookup and Hibernate initialization will fail. Unfortunately, order of persister creation is a little bit stochastic and determined by HashMap implementation (see, SessionFacoryImpl.java:181). Giving the following example: <?xml version="1.0" encoding="windows-1252"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="SuperType"> <id name="identifier" column="identifier" type="long"> <generator class="increment"/> </id> <union-subclass name="SubType" table="SUBTYPE"> <property name="label" column="LABEL" type="string" not-null="true"/> </union-subclass> <union-subclass name="SubType2" table="SUBTYPE2"> <many-to-one name="dependentObject" class="DependentObject" column="idDependentObject"/> </union-subclass> </class> <class name="DependentObject"> <id name="identifier" column="identifier" type="long"> <generator class="increment"/> </id> </class> </hibernate-mapping> The initialisation of UnionsubclassEntityPersister for SuperType fails with the following stack-trace since persister for DependentObject have not been yet created: org.hibernate.MappingException: Could not determine type for column idDependentObject of type org.hibernate.type.ManyToOneType: org.hibernate.MappingException at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:131) at org.hibernate.persister.entity.UnionSubclassEntityPersister.generateSubquery(UnionSubclassEntityPersister.java:320) at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:135) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043) at M.main(M.java:48) Caused by: org.hibernate.MappingException: Unknown entity: DependentObject at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:489) at org.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:563) at org.hibernate.type.EntityType.getIdentifierType(EntityType.java:216) at org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:226) at org.hibernate.type.ManyToOneType.sqlTypes(ManyToOneType.java:29) at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:124) ... 11 more Actually, renaming of DependentObject to ADependentObject will hide a bug since PersistentClass object for ADependentObject will become a first item in the list (actually HashMap with name of class as key) of classes to construct a persister. Possible solution: make initialisation of persister class in two phases. While first phase we will construct persister's basic structures _for all persistent classes_, and then we will initialise the rest of persistors' properties which can depend upon other persistors.

    Hibernate JIRA | 1 decade ago | Vladimir Demochko
    org.hibernate.MappingException: Could not determine type for column idDependentObject of type org.hibernate.type.ManyToOneType: org.hibernate.MappingException
  2. 0

    Constructor of UnionsubclassEntityPersister initialize an objects loading SQL query in generateSubquery(PersistentClass) method. While construction of this SQL query method Column.getSqlTypeMethod(Mapping) is called (UnionsubclassEntityPersister.java:320) to determine NULL expression to be used. If column in question is a reference to an associated class (for example, an identifier for many-to-one relation), column will look for referenced entity primary key type. However, if the persister for referenced entity has not been yet created column type lookup and Hibernate initialization will fail. Unfortunately, order of persister creation is a little bit stochastic and determined by HashMap implementation (see, SessionFacoryImpl.java:181). Giving the following example: <?xml version="1.0" encoding="windows-1252"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="SuperType"> <id name="identifier" column="identifier" type="long"> <generator class="increment"/> </id> <union-subclass name="SubType" table="SUBTYPE"> <property name="label" column="LABEL" type="string" not-null="true"/> </union-subclass> <union-subclass name="SubType2" table="SUBTYPE2"> <many-to-one name="dependentObject" class="DependentObject" column="idDependentObject"/> </union-subclass> </class> <class name="DependentObject"> <id name="identifier" column="identifier" type="long"> <generator class="increment"/> </id> </class> </hibernate-mapping> The initialisation of UnionsubclassEntityPersister for SuperType fails with the following stack-trace since persister for DependentObject have not been yet created: org.hibernate.MappingException: Could not determine type for column idDependentObject of type org.hibernate.type.ManyToOneType: org.hibernate.MappingException at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:131) at org.hibernate.persister.entity.UnionSubclassEntityPersister.generateSubquery(UnionSubclassEntityPersister.java:320) at org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:135) at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043) at M.main(M.java:48) Caused by: org.hibernate.MappingException: Unknown entity: DependentObject at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:489) at org.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:563) at org.hibernate.type.EntityType.getIdentifierType(EntityType.java:216) at org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:226) at org.hibernate.type.ManyToOneType.sqlTypes(ManyToOneType.java:29) at org.hibernate.mapping.Column.getSqlTypeCode(Column.java:124) ... 11 more Actually, renaming of DependentObject to ADependentObject will hide a bug since PersistentClass object for ADependentObject will become a first item in the list (actually HashMap with name of class as key) of classes to construct a persister. Possible solution: make initialisation of persister class in two phases. While first phase we will construct persister's basic structures _for all persistent classes_, and then we will initialise the rest of persistors' properties which can depend upon other persistors.

    Hibernate JIRA | 1 decade ago | Vladimir Demochko
    org.hibernate.MappingException: Could not determine type for column idDependentObject of type org.hibernate.type.ManyToOneType: org.hibernate.MappingException
  3. 0

    Login form based spring 3 security example - HowToDoInJava

    howtodoinjava.com | 11 months ago
    org.hibernate.MappingException: Unknown entity: from employee
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Hibernate can not save object

    Stack Overflow | 1 year ago | o1ctav
    org.hibernate.MappingException: Unknown entity: com.simpleprogrammer.User
  6. 0

    spring-boot, spring security, spring web with maven, jboss and eclipse

    sc0713.com | 4 months ago
    org.springframework.orm.hibernate4.HibernateSystemException: Unknown entity: java.util.HashSet; nested exception is org.hibernate.MappingException: Unknown entity: java.util.HashSet

    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

      Unknown entity: DependentObject

      at org.hibernate.impl.SessionFactoryImpl.getEntityPersister()
    2. Hibernate
      SessionFactoryImpl.getIdentifierType
      1. org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:489)
      2. org.hibernate.impl.SessionFactoryImpl.getIdentifierType(SessionFactoryImpl.java:563)
      2 frames
    3. Hibernate
      UnionSubclassEntityPersister.<init>
      1. org.hibernate.type.EntityType.getIdentifierType(EntityType.java:216)
      2. org.hibernate.type.EntityType.getIdentifierOrUniqueKeyType(EntityType.java:226)
      3. org.hibernate.type.ManyToOneType.sqlTypes(ManyToOneType.java:29)
      4. org.hibernate.mapping.Column.getSqlTypeCode(Column.java:124)
      5. org.hibernate.mapping.Column.getSqlTypeCode(Column.java:131)
      6. org.hibernate.persister.entity.UnionSubclassEntityPersister.generateSubquery(UnionSubclassEntityPersister.java:320)
      7. org.hibernate.persister.entity.UnionSubclassEntityPersister.<init>(UnionSubclassEntityPersister.java:135)
      7 frames
    4. Hibernate
      SessionFactoryImpl.<init>
      1. org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:61)
      2. org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
      2 frames
    5. Hibernate
      Configuration.buildSessionFactory
      1. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1043)
      1 frame
    6. Unknown
      M.main
      1. M.main(M.java:48)
      1 frame