我正在尝试检索将通过字符串启动解析到UI的数据,但是我一直遇到一个长错误,我知道这是由于@oneToMany映射所致:
java.lang.StackOverflowError: null
at java.util.concurrent.ConcurrentHashMap.putVal(ConcurrentHashMap.java:1012) ~[na:1.8.0_162]
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1535) ~[na:1.8.0_162]
at java.lang.ClassLoader.getClassLoadingLock(ClassLoader.java:463) ~[na:1.8.0_162]
at java.lang.ClassLoader.loadClass(ClassLoader.java:404) ~[na:1.8.0_162]
at java.lang.ClassLoader.loadClass(ClassLoader.java:411) ~[na:1.8.0_162]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) ~[na:1.8.0_162]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_162]
at org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printCollection(JavaScriptUtils.java:322) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:173) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printKeyValue(JavaScriptUtils.java:346) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printMap(JavaScriptUtils.java:337) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printObject(JavaScriptUtils.java:365) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:184) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.printCollection(JavaScriptUtils.java:322) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.thymeleaf.util.JavaScriptUtils.print(JavaScriptUtils.java:173) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]
我有ClothModel和Tasks类两个类。
@Entity
public class Task extends DefaultEntity{
@ManyToOne
@JoinColumn(name = "cloth_model_id")
private ClothModel clothModel;
private String details;
private boolean completed;
@ManyToOne
@JoinColumn(name = "employee_id")
private Employee employee;
@JsonBackReference
public ClothModel getClothModel() {
return clothModel;
}
public void setClothModel(ClothModel clothModel) {
this.clothModel = clothModel;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public boolean isCompleted() {
return completed;
}
public void setCompleted(boolean completed) {
this.completed = completed;
}
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
}
@Entity
public class ClothModel extends DefaultEntity {
private ClothingType clothingType;
private int quantity;
private double amount;
@Transient
private String modelStructure;
private String savedUrl;
@Transient
@Fetch(value = FetchMode.SELECT)
@JsonManagedReference
private List<Task> tasks = new ArrayList<>();
public List<Task> getTasks() {
return tasks;
}
public ClothModel setTasks(List<Task> tasks) {
this.tasks = tasks;
return this;
}
public ClothModel setTask(Task tasks) {
this.tasks.add(tasks);
return this;
}
public ClothingType getClothingType() {
return clothingType;
}
public ClothModel setClothingType(ClothingType clothingType) {
this.clothingType = clothingType;
return this;
}
public int getQuantity() {
return quantity;
}
public ClothModel setQuantity(int quantity) {
this.quantity = quantity;
return this;
}
public double getAmount() {
return amount;
}
public ClothModel setAmount(double amount) {
this.amount = amount;
return this;
}
public String getModelStructure() {
return modelStructure;
}
public ClothModel setModelStructure(String modelStructure) {
this.modelStructure = modelStructure;
return this;
}
public String getSavedUrl() {
return savedUrl;
}
public void setSavedUrl(String savedUrl) {
this.savedUrl = savedUrl;
}
}
我的主要问题是:
我能够通过和api调用将ClothModel实体保存/更新到数据库,但是当我想检索一个ClothModel时,它崩溃了,我确信它具有List Tasks属性。 / p>
使用@JsonManagedReference和@JsonBackReference并没有帮助,因为它仍然会给我错误。
有人可以协助我阻止这种错误