2 Replies Latest reply on Jan 21, 2007 7:11 AM by lajosgathy

    Embedded Objects set to null by entitymanager

    mwoelke

      Hi,
      We've got a problem with embedded objects. Imagine the following scenario:

      @Entity
      class A{
       int id;
       B embedded;
      
       public A(){
       embedded = new B();
       }
      
       @Embedded
       public B getEmbedded(){
       return embedded;
       }
      
       ... other getters and setters ... nothing special ...
      }
      
      @Embeddable
      class B{
       String name;
       String shortName;
       public String getName(){...}
       public String getShortName(){...}
       ... setters ...
      }


      If name or shortName of B is set to a value other than null everything works fine, which means A.embedded is set to a non null value when fetching it from the db. BUT, if both properties of B are set to null, A.embedded itself is set to null, too.
      This happens although the default constructor which gets called by the entity manager sets it to a non null value.

      Does anyone know this behavior? Is it what its is supposed to be? And how to deal with that if its necessary to have A.embedded always set to a non null value.

      We are still using JBoss 4.0.4 RC1. Is this a known issue? Should we switch to 4.0.4GA? Any help is appreciated.

      Thanx in advance.

      Milan Wölke