5 Replies Latest reply on Mar 9, 2006 2:32 PM by Michael Newcomb

    @Embedded objects require @AttributeOverrides? WTF!?

    Michael Newcomb Newbie

      JDK 1.5.0_06
      JBoss 4.0.4RC1

      @Embeddable
      class Vector3f
      {
       double getX()
       double getY()
       double getZ()
      }
      
      @Entity
      class Foo
      {
       @Embedded
       Vector3f getVelocity();
       @Embedded
       Vector3f getOrientation();
      }


      I get some errors from Hibernate about multiple columns in the Foo table. The only way it works is if I add @AttributeOverrides and specify unique columns for each embedded object.

      @Entity
      class Foo
      {
       @Embedded
       @AttributeOverrides(
       {
       @AttributeOverride(name="x", column=@Column(name="velocity_x")),
       @AttributeOverride(name="x", column=@Column(name="velocity_y")),
       @AttributeOverride(name="x", column=@Column(name="velocity_z"))
       }
       Vector3f getVelocity();
      
       @Embedded
       @AttributeOverrides(
       {
       @AttributeOverride(name="x", column=@Column(name="orientation_x")),
       @AttributeOverride(name="x", column=@Column(name="orientation_y")),
       @AttributeOverride(name="x", column=@Column(name="orientation_z"))
       }
       Vector3f getOrientation();
      }


      This is, IMHO, incredibly stupid. We are embedding the structure of the embedded class... WTF good is the embedded class? What happens when I want to add a member? Or change the names?

      Now, in older JBoss versions, the CMP container added the field name of the embedded class as a prefix to the fields in the embedded class. Much like the above:

      velocity_x
      velocity_y
      velocity_z
      orientation_x
      orientation_y
      orientation_z


      Am I doing something wrong?

      Thanks,
      Michael