2 Replies Latest reply on Feb 11, 2009 4:23 AM by marco petracca

    _$$_javassist_

    marco petracca Newbie

      ciao,


      I am trying to use envers in my applications where the entity are mapped by hbm.xml.

      in this line I have an error
      IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();

      the problem is the toEntityName because the value is

      myclass.name+_$$_javassist_+number

      and in the verCfg do not present a mapper.


      I think is the no JPA mapping in my entity.
      Is it possible!?


      I modify AuditEventListener


      private void generateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, EntityPersister entityPersister,
      String entityName, Object[] newState, Object[] oldState,
      SessionImplementor session) {
      // Checking if this is enabled in configuration ...
      if (!verCfg.getGlobalCfg().isGenerateRevisionsForCollections()) {
      return;
      }

      // Checks every property of the entity, if it is an "owned" to-one relation to another entity.
      // If the value of that property changed, and the relation is bi-directional, a new revision
      // for the related entity is generated.
      String[] propertyNames = entityPersister.getPropertyNames();

      for (int i=0; i<propertyNames.length; i++) {
      String propertyName = propertyNames;
      RelationDescription relDesc = verCfg.getEntCfg().getRelationDescription(entityName, propertyName);
      if (relDesc != null && relDesc.isBidirectional() && relDesc.getRelationType() == RelationType.TO_ONE) {
      // Checking for changes
      Object oldValue = oldState == null ? null : oldState
      ;
      Object newValue = newState == null ? null : newState;

      if (!Tools.objectsEqual(oldValue, newValue)) {
      // We have to generate changes both in the old collection (size decreses) and new collection
      // (size increases).
      if (newValue != null) {
      // relDesc.getToEntityName() doesn't always return the entity name of the value - in case
      // of subclasses, this will be root class, no the actual class. So it can't be used here.
      String toEntityName = session.guessEntityName(newValue);

      //patch for no JPA mapping
      int _$$_javassist_= toEntityName.indexOf("_$$_javassist_");
      if(_$$_javassist_!=-1)
      toEntityName = toEntityName.substring(0, _$$_javassist_);

      IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();

      Serializable id = (Serializable) idMapper.mapToIdFromEntity(newValue);
      verSync.addWorkUnit(new CollectionChangeWorkUnit(toEntityName, verCfg, id, newValue));
      }

      if (oldValue != null) {
      String toEntityName = session.guessEntityName(oldValue);

      //patch for no JPA mapping
      int _$$_javassist_= toEntityName.indexOf("_$$_javassist_");
      if(_$$_javassist_!=-1)
      toEntityName = toEntityName.substring(0, _$$_javassist_);


      IdMapper idMapper = verCfg.getEntCfg().get(toEntityName).getIdMapper();

      Serializable id = (Serializable) idMapper.mapToIdFromEntity(oldValue);
      verSync.addWorkUnit(new CollectionChangeWorkUnit(toEntityName, verCfg, id, oldValue));
      }
      }
      }
      }
      }

      sorry for my poor english :-P
      tnx