Hello everyone!
Description:
We are using the tag @OneToMany to map a collection of objects in an entity. In the other side, we use the tag @ManyToOne to map the father.
Our simple example for testing consist of the following entities:
This is the class Child:
@Entity
@Table(name="TEST_CHILD")
public class Child implements Serializable{
@Id
@Column(name="ID_CHILD")
private Long id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ID_FATHER", referencedColumnName="ID_FATHER")
private Father father;
and this is the Father class:
@Entity
@Table(name="TEST_FATHER")
public class Father implements Serializable{
@Id
@Column(name="ID_FATHER")
private Long id;
@OneToMany(mappedBy="father", fetch=FetchType.EAGER)
private List<Child> children;
Problem:
When a select over this entities is realized, we are getting the folling exception:
The following Error is thrown by the VM [java.lang.StackOverflowError]. ErrorQueueHandler will just trace it. The caller component should take care to process it properly.
java.lang.StackOverflowError
at java.lang.Class.searchMethods(Class.java:2646)
We've already used @OneToMany and @ManyToOne mapping in many other projects, and we've tried different parameters on the tags as well, but we still getting the exception. If applying fetch mode Lazy to the @OneToMany we had an detatched exception, cause ou the context. Anyways, we need and would like to use the EAGER loading mode.
So what seems to happen is that the application runs into a cycle when loading the "father" attribute of Child, recreating the list collection within it.
This same configuration works just fine in other implementations (i.e.: Hibernate JPA implementation), and many other examples over the web are not different of our implementation.
Any suggestion of how we could solve this problem? Is this a standart behavior of mapping using Sap JPA?
Evandro Pomatti
Edited by: Evandro Pomatti on Dec 9, 2010 9:55 PM