Hi,
I have a scenario where class A contains object of class B and class B in
turn contains object of class C. According to JPA specs nesting of
embeddable tag is not supported (in OpenJPA). But I am trying the workaround
mentioned in section 2.4 of the following link:
http://en.wikibooks.org/wiki/Java_Persistence/Embeddables
I am not able to do it properly and getting the exception:
WARN [main] openjpa.Enhance - [Possible violation of subclassing contract
detected while processing persistent field com.entity.B.data, declared in
E:\Workspace\JPA\bin\com\entity\B.class. Are you sure you are obeying the
OpenJPA requirements? Details: The getter for field data does not obey
OpenJPAs subclassing restrictions. Getters must return a single non-computed
field., Possible violation of subclassing contract detected while processing
persistent field com.entity.B.data, declared in
E:\Workspace\JPA\bin\com\entity\B.class. Are you sure you are obeying the
OpenJPA requirements? Details: The setter for field data does not obey
OpenJPAs subclassing restrictions. Setters must assign the passed-in
parameter to a single field in the object.]
org.apache.openjpa.persistence.RollbackException: Missing field for
property "data" in type "class com.entity.B".
-------------------------------------------------------------
The code is hereunder:
CLASS A
@Entity(name="A")
public class A {
private int id;
private String name;
private B b;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Embedded
public B getB() {
return b;
}
public void setB(B b) {
this.b = b;
}
}
CLASS B
@Embeddable
public class B {
private int age;
private C c;
@Basic
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Embedded
public C getC() {
return c;
}
public void setC(C c) {
this.c = c;
}
@Basic
public int getData() {
return getC().getData();
}
public void setData(int data) {
getC().setData(data);
}
}
CLASS C
@Embeddable
public class C {
private int data;
@Basic
public int getData() {
return data;
}
public void setData(int data) {
this.data = data;
}
}
TEST CLASS
public class AnnotationTest {
private static EntityManagerFactory emf = null;
public static void main(String[] args) {
A a = new A();
B b = new B();
C c = new C();
c.setData(1);
b.setAge(21);
b.setC(c);
a.setName("Kamlesh");
a.setB(b);
EntityManager em = getEMF().createEntityManager();
try {
em.getTransaction().begin();
em.persist(a);
em.getTransaction().commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
em.close();
}
}
public static EntityManagerFactory getEMF() {
if (emf == null) {
emf = Persistence.createEntityManagerFactory("ibm");
System.out.println("emf " + emf);
}
return emf;
}
}
I guess there is some problem with the way I am using Property access.
Please tell me what mistake I am doing.
Regards,
KK
--
Sent from the OpenJPA Users mailing list archive at Nabble.com.