问题
I have two tables Folder & VirtualSystemEntry I tried to follow this Dataneclous Turorial but it always results with StackOverFlowException here what I tried so far
Folder.java
@Entity
public class Folder implements IsSerializable{
@Id
@Column(name = "fvseID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String fvseID;
@OneToOne
@JoinColumn(name="vseID")
private VirtualSystemEntry vse=new VirtualSystemEntry();
}
VirtualSystemEntry.java
@Entity
public class VirtualSystemEntry implements IsSerializable {
@Id
@Column(name = "vseID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String id;
String label, image, tooltip;
private int x, y, tray;
@OneToOne(mappedBy="vse")
Folder parent = new Folder();
}
Piece of the Exception Trace
INTERNAL_SERVER_ERROR</pre></p><h3>Caused by:</h3><pre>java.lang.StackOverflowError
at java.util.Hashtable.get(Hashtable.java:334)
at java.util.Properties.getProperty(Properties.java:932)
at java.lang.System.getProperty(System.java:653)
at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:63)
at com.cbd.shared.entities.VirtualSystemEntry.<init>(VirtualSystemEntry.java:28)
at com.cbd.shared.entities.Folder.<init>(Folder.java:27)
at com.cbd.shared.entities.VirtualSystemEntry.<init>(VirtualSystemEntry.java:28)
at com.cbd.shared.entities.Folder.<init>(Folder.java:27)
at com.cbd.shared.entities.VirtualSystemEntry.<init>(VirtualSystemEntry.java:28)
at com.cbd.shared.entities.Folder.<init>(Folder.java:27)
at com.cbd.shared.entities.VirtualSystemEntry.<init>(VirtualSystemEntry.java:28)
at com.cbd.shared.entities.Folder..... and so on
So What am I doing wrong right here ?? by the way I'm Using GWT
回答1:
So your code VirtualSystemEntry(constructor) is calling your code Folder(constructor), which recurses (and you don't provide the code of those methods), likely the initialisation of those class variables "parent" and "vse" ... fix the initialisation ;-)
来源:https://stackoverflow.com/questions/16855390/stackoverflowerror-while-doing-a-one-to-one-relationship-in-gae-datastore-using