该错误似乎是一个递归错误,该公司要求 Worksheets 再次要求公司,这....您得到了漂移。我已经为此搜索了互联网和堆栈溢出,我发现了错误发生的原因,但解决方案始终是编写自己的解析器或使用 flexjson 或其他。我只是想知道是否有解决方案,因为游戏非常流行,而且人们肯定会在一次操作中获取帖子和评论,或者不是吗?
必须有一个解决方案,无需更换 json 解析器或编写自己的解析器。
公司.java
package models;
import java.util.*;
import javax.persistence.*;
import play.db.jpa.*;
@Entity
public class Company extends Model {
public String name;
public String address;
public String city;
public String zipcode;
public String country;
public String phonenumber;
public String website;
public String footer;
public String maincontactperson;
public String email;
public String password;
public Blob logo;
@OneToMany(mappedBy = "company", cascade = CascadeType.ALL, orphanRemoval = true, fetch=FetchType.EAGER)
public List<Worksheet> worksheets;
}
}
和
工作表.java
package models;
import java.util.*;
import javax.persistence.*;
import play.db.jpa.*;
@Entity
public class Worksheet extends Model {
public String contactname;
public String name;
public String address;
public String phonenumber;
public String city;
public String email;
public String partnumber;
@Lob
public String partdescription;
public String password;
public Date due_date;
public Date in_date;
@Lob
public String notes;
@ManyToOne(cascade=CascadeType.ALL)
public Company company;
...
}
在我的控制器中,我只是运行这个:
List<Company> companies = Company.FindAll();
renderJSON(companies);
如果没有工作表,这可以工作,但是一旦有工作表,它就会崩溃并显示一英里长的错误消息。这是它的顶部:
00:31:02,623 ERROR ~
@6cbn7gi1o
Internal Server Error (500) for request POST /companies/login
Execution exception
InvocationTargetException occured : null
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:239)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.reflect.InvocationTargetException
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:557)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:508)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:484)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:479)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
Caused by: java.lang.StackOverflowError
at java.util.Date.getTimeImpl(Date.java:870)
at java.util.Date.getTime(Date.java:866)
at java.sql.Timestamp.getTime(Timestamp.java:126)
at java.util.Calendar.setTime(Calendar.java:1076)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:875)
at java.text.SimpleDateFormat.format(SimpleDateFormat.java:868)
at java.text.DateFormat.format(DateFormat.java:316)
at com.google.gson.internal.bind.DateTypeAdapter.write(DateTypeAdapter.java:90)
at com.google.gson.internal.bind.DateTypeAdapter.write(DateTypeAdapter.java:41)
at com.google.gson.internal.bind.TypeAdapters$22$1.write(TypeAdapters.java:522)
at com.google.gson.internal.bind.TypeAdapters$22$1.write(TypeAdapters.java:515)
....
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)
at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:879)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:89)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:195)