title: Hibernate Entity proxy initialization
body: <p>I'm having a problem with a Hibernate entity that does not get initialised.<br/> 
  It seems that it's still returning a not initialised proxy...</p>
  
  <p>If I take a look at my debug info I would expect my entity to be initialised.<br/>
  But it looks like the following:</p>
  
  <pre><code>entity = {SomeEntity_$$_jvst47c_1e@9192}"SomeEntityImpl@1f3d4adb[id=1,version=0]"
      handler = {org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer@9196}
          interfaces = {java.lang.Class[2]@9197}
          constructed = true
          persistentClass = {java.lang.Class@3605}"class SomeEntityImpl"
          getIdentifierMethod = null
          setIdentifierMethod = null
          overridesEquals = true
          componentIdType = null
          replacement = null
          entityName = {java.lang.String@9198}"SomeEntityImpl"
          id = {java.lang.Long@9199}"1"
          target = {SomeEntityImpl@9200}"SomeEntityImpl@1f3d4adb[guid=&lt;null&gt;,id=1,version=0]"
          initialized = true
          readOnly = true
          unwrap = false
          session = {org.hibernate.internal.SessionImpl@6878}"SessionImpl(PersistenceContext[entityKeys=[EntityKey[EntityReferenceImpl#2], EntityKey[SomeEntityImpl#1], EntityKey[...
          readOnlyBeforeAttachedToSession = null
          sessionFactoryUuid = null
          allowLoadOutsideTransaction = false
  </code></pre>
  
  <p>Notice that my Hibernate POJO still only contains a <code>handler</code>even after doing an explicit initialisation... <br/>
  In my debug view, I can see the 'real' property values (not displayed above) when I expand the <code>target</code> node.</p>
  
  <p>What I'm doing:</p>
  
  <pre><code>EntityReferenceImpl entityReference = findEntityReference(session);
  SomeEntity entity = null;
  if (entityReference != null) {
      // initialize association using a left outer join
      HibernateUtil.initialize(entityReference.getSomeEntity());
      entity = entityReference.getSomeEntity();
  }
  return entity;
  </code></pre>
  
  <p>Notice the <code>HibernateUtil.initialize</code> call! </p>
  
  <p><code>SomeEntity</code> mapping:</p>
  
  <pre><code>public class SomeEntityImpl extends AbstractEntity implements SomeEntity {
      @OneToMany(mappedBy = "someEntity", fetch = FetchType.EAGER, targetEntity = EntityReferenceImpl.class, orphanRemoval = true)
      @Cascade(CascadeType.ALL)
      @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
      private Set&lt;EntityReference&gt; entityReferences = new HashSet&lt;&gt;();
  
      @Target(EntityName.class)
      @Embedded
      private Name name;
  
      @Target(EntityAddress.class)
      @Embedded
      private Address address;
  
      ...
  
  }
  </code></pre>
  
  <p><code>EntityReferenceImpl</code> mapping:</p>
  
  <pre><code>public class EntityReferenceImpl extends AbstractEntity implements EntityReference {
  
  @ManyToOne(optional = true, fetch = FetchType.LAZY, targetEntity = SomeEntityImpl.class)
  @JoinColumn(name = "entity_id")
  private SomeEntity someEntity;
  
  ...
  
  }
  </code></pre>
  
  <p>So what is the side effect: When the POJO later comes with updated properties I'm still having the same structure (as mentioned above) and I can see the updated properties under the <code>target</code> node. 
  <br/>
  But when I'm trying to update the entity using <code>session.merge()</code> or <code>session.update()</code>or <code>session.saveOrUpdate()</code>, Hibernate does not detect the 'dirty' properties and does not invoke an update query to the database.</p>
  
  <p><br/>
  Does anyone have some clues about this weird behavior? I have tried everything what I can but without any results.
  <br/>
  All help is very welcome!!
  <br/></p>