3 Replies Latest reply on Dec 8, 2009 1:17 AM by asdf asdf

    Mapping exception when one class maps to multiple tables.

    asdf asdf Newbie

      Hi Everyone,

      I have successfully added envers to my spring hibernate configuration, its working fine for simple features. Im exploring with different scenarios
      For example , Address entity object maps to multiple tables (as shown in the configuration), and has the many to one relation with person entity, when Im trying to save the person entity, getting below error message.

      org.hibernate.MappingException: Unknown entity: envers.domainobjects.Address
      at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)
      at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366)
      at org.hibernate.envers.tools.Tools.getIdentifier(Tools.java:67)
      at org.hibernate.envers.tools.Tools.entitiesEqual(Tools.java:50)
      at org.hibernate.envers.entities.mapper.relation.ToOneIdMapper.mapToMapFromEntity(ToOneIdMapper.java:65)
      at org.hibernate.envers.entities.mapper.MultiPropertyMapper.map(MultiPropertyMapper.java:86)
      at org.hibernate.envers.synchronization.work.AddWorkUnit.perform(AddWorkUnit.java:60)
      at org.hibernate.envers.synchronization.AuditSync.executeInSession(AuditSync.java:125)
      at org.hibernate.envers.synchronization.AuditSync.beforeCompletion(AuditSync.java:164)
      at org.hibernate.transaction.JDBCTransaction.notifyLocalSynchsBeforeTransactionCompletion(JDBCTransaction.java:274)
      at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:140)
      at envers.test.TestAuditLogs.createPersonAndAddress(TestAuditLogs.java:179)
      at envers.test.TestAuditLogs.main(TestAuditLogs.java:80)

      address.hbm.xml file :
      ----------------------
      <class name="envers.domainobjects.Address" table="POSTAL_ADDRESS" entity-name="postalAddress">
       <id name="id" column="ID" type="long">
       <generator class="increment" />
       </id>
       <property name="streetName" type="string">
       <column name="streetName" />
       </property>
       <property name="houseNumber" type="int">
       <column name="houseNumber" />
       </property>
       <property name="flatNumber" type="int">
       <column name="flatNumber" />
       </property>
      </class>
      <class name="envers.domainobjects.Address" table="BILLING_ADDRESS"
       entity-name="billingAddress">
       <id name="id" column="ID" type="long">
       <generator class="increment" />
       </id>
       <property name="streetName" type="string">
       <column name="streetName" />
       </property>
       <property name="houseNumber" type="int">
       <column name="houseNumber" />
       </property>
       <property name="flatNumber" type="int">
       <column name="flatNumber" />
       </property>
       </class>
      
      
      Person.hbm.xml file:
      ---------------------
      
      <class name="envers.domainobjects.Person" table="PERSON">
       <id name="id" column="ID" type="long">
       <generator class="increment" />
       </id>
       <property name="name" type="string">
       <column name="NAME" />
       </property>
       <property name="surname" type="string">
       <column name="surname" />
       </property>
       <many-to-one name="postalAddress" class="envers.domainobjects.Address"
       entity-name="postalAddress" column="postal_address_Id" unique="true" />
       <many-to-one name="billingAddress" class="envers.domainobjects.Address"
       entity-name="billingAddress" column="billing_address_Id" unique="true" />
      </class>


      Any help would be appreciated.


      Thanks
      skhan.