@Override
 public Object getImplementation(SessionImplementor session) throws HibernateException {
   Object oldTarget = this.oldTarget;
   Object target = this.lazyInitializer.getImplementation(session);
   if (oldTarget != target) {
     ScalarListener listener = this.new TargetScalarListener();
     if (oldTarget != null) {
       this.omFactory.get(oldTarget).removeScalarListener(listener);
     }
     this.oldTarget = target;
     if (target != null) {
       ObjectModel targetOM = this.omFactory.get(target);
       targetOM.removeScalarListener(listener); // remove the duplicated listener.
       targetOM.addScalarListener(listener);
     }
   }
   return target;
 }
 @Override
 public void setImplementation(Object target) {
   LazyInitializer rawLazyInitializer = this.lazyInitializer;
   Object oldTarget =
       rawLazyInitializer.isUninitialized() ? null : rawLazyInitializer.getImplementation();
   if (target != oldTarget) {
     ScalarListener listener = this.new TargetScalarListener();
     if (oldTarget != null) {
       this.omFactory.get(oldTarget).removeScalarListener(listener);
     }
     rawLazyInitializer.setImplementation(target);
     this.oldTarget = target;
     if (target != null) {
       ObjectModel targetOM = this.omFactory.get(target);
       targetOM.removeScalarListener(listener); // remove the duplicated listener.
       targetOM.addScalarListener(listener);
     }
   }
 }
 @SuppressWarnings("unchecked")
 private void initTransient(Class<?> persistentClass) {
   LazyInitializer rawLazyInitializer = this.lazyInitializer;
   if (persistentClass == null) {
     persistentClass = getPersistentClass((BasicLazyInitializer) rawLazyInitializer);
   }
   HibernateObjectModelMetadata objectModelMetadata = HibernateMetadatas.of(persistentClass);
   this.objectModelMetadata = objectModelMetadata;
   this.omFactory =
       (ObjectModelFactory<ObjectModel>)
           ObjectModelFactoryFactory.factoryOf(objectModelMetadata.getObjectModelClass());
   try {
     this.getIdentifierMethod = (Method) GET_IDENTIFIER_METHOD_FIELD.get(rawLazyInitializer);
     this.setIdentifierMethod = (Method) SET_IDENTIFIER_METHOD_FIELD.get(rawLazyInitializer);
   } catch (IllegalArgumentException | IllegalAccessException e) {
     throw new AssertionError();
   }
   if (!rawLazyInitializer.isUninitialized()) {
     ObjectModel targetOM = this.omFactory.get(rawLazyInitializer.getImplementation());
     ScalarListener listener = this.new TargetScalarListener();
     targetOM.removeScalarListener(listener);
     targetOM.addScalarListener(listener);
   }
 }