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

    _$$_javassist_

    marcopt

      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

        • 1. Re: _$$_javassist_
          adamw

          Hello,

          not long ago a user submitted a patch for a very similar issue. The patch is now applied to trunk and the hibernate-3.3 branch. So maybe you could try with one of those?

          --
          Adam

          • 2. Re: _$$_javassist_
            marcopt

             

            "adamw" wrote:
            Hello,

            not long ago a user submitted a patch for a very similar issue. The patch is now applied to trunk and the hibernate-3.3 branch. So maybe you could try with one of those?

            --
            Adam


            tnx Adam

            I saw the patch :-P .

            Marco