AttributeOverride establece un valor nulo en un campo sin asignar

tengo clase

@Embeddable
public class MyClass implements Serializable
{
   private String field1;
   private String field2;
   private String field3;

// getters, setters
}

and I have mapped class

public class MappedClass implements Serializable
{
   @Embedded
   @AttributeOverrides(
      {
        @AttributeOverride(name = "field1", column = @Column(name = "column1")),
        @AttributeOverride(name = "field2", column = @Column(name = "column2")),
        @AttributeOverride(name = "field3", column = @Column(name = "column3"))
      })
   private MyClass myClassField1;

   @Embedded
   @AttributeOverrides(
      {
        @AttributeOverride(name = "field1", column = @Column(name = "column1")),
        @AttributeOverride(name = "field2", column = @Column(name = "column2")),
      })
   private MyClass myClassField2;

// setters, getters

}

I want that 'filed3' in myClassField2 be 'null', becouse 'field3' hasn't DB mapping. What can I do? JPA search value for 'field3' in column 'field3'

In Hibernate all passed normal!

   <component name="myClassField1" class="MappedClass">
           <property name="field1" type="string" column="column1" />
           <property name="field2" type="string" column="column2" />
           <property name="field3" type="string" column="column3" />
   <component/>  

   <component name="myClassField2" class="MappedClass">
           <property name="field1" type="string" column="column1" />
           <property name="field2" type="string" column="column2" />
   <component/>  

But I need this in JPA

preguntado el 09 de marzo de 12 a las 13:03

1 Respuestas

What you want to do is impossible. EIther a field is persistent, or it's transient. It can't be sometimes one and sometimes the other.

Consider defining a MyClass1 with just two fields, and a MyClass2 extending MyClass1 and adding the third field. Use the first one for myClassField2, y el segundo para myClassField1.

Note that, in your example, you have mapped column1 and column2 twice, which is also incorrect.

respondido 09 mar '12, 17:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.