进行查询的陷入了无限死循环,原因是问题类中包含了回答,回答类中包含了问题,进入了无限死循环

解决方法:在回答类中的问题类属性上加注解:@JsonBackReference

问题中有回答的set集合,回答中有问题类:

问题类:

package com.wazn.learn.entity.teachclass;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set; import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table; import com.wazn.learn.entity.sys.User; /**
*
* 提问表
*
*/
@Entity
@Table(name="teach_questions")
public class Questions {
private Integer id;//id
private User userid;//学生id
private TeachClass cid;//课程id
private String question;//提问
private Date twtime;//提问时间
private String title;
private Set<Answer> answer; @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
} @Column(nullable=false) public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
@ManyToOne
@JoinColumn(name="c_id",nullable=false,insertable=true)
public TeachClass getCid() {
return cid;
}
public void setCid(TeachClass cid) {
this.cid = cid;
}
@ManyToOne
@JoinColumn(name="user_id",nullable=false,insertable=true)
public User getUserid() {
return userid;
}
public void setUserid(User userid) {
this.userid = userid;
}
public Date getTwtime() {
return twtime;
}
public void setTwtime(Date twtime) {
this.twtime = twtime;
} @OneToMany(cascade = { CascadeType.REFRESH, CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE },mappedBy ="question")
public Set<Answer> getAnswer() {
return answer;
}
public void setAnswer(Set<Answer> answer) {
this.answer = answer;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}

回答类:

package com.wazn.learn.entity.teachclass;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table; import com.fasterxml.jackson.annotation.JsonBackReference;
import com.wazn.learn.entity.sys.User;
@Entity
@Table(name="teach_answer")
public class Answer { private Integer id;
private String content;
private Date hftime;
private User userid;//教师id
private Questions question; @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
} @Column(nullable=false)
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
} public Date getHftime() {
return hftime;
}
public void setHftime(Date hftime) {
this.hftime = hftime;
}
@ManyToOne
@JoinColumn(name="u_id",nullable=false,insertable=true)
public User getUserid() {
return userid;
}
public void setUserid(User userid) {
this.userid = userid;
} @ManyToOne
@JoinColumn(name="q_id",nullable=false,insertable=true)
@JsonBackReference
public Questions getQuestion() {
return question;
}
@JsonBackReference
public void setQuestion(Questions question) {
this.question = question;
}
@Override
public String toString() {
return "Answer [id=" + id + ", content=" + content + ", hftime=" + hftime + ", userid=" + userid + ", question="
+ question + "]";
} }

spring mvc报错,数据库查询无限死循环的更多相关文章

  1. Spring mvc 报错:No qualifying bean of type [java.lang.String] found for dependency:

    具体错误: No qualifying bean of type [java.lang.String] found for dependency: expected at least 1 bean w ...

  2. SpringBoot、Spring MVC报错:Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

    出现问题的原因: jdbc配置不正确 解决方案: 1.检查是否已添加数据库驱动jar包 2.检查数据库服务是否启动 3.检查数据库配置文件 主要为:dialect,driver_class,url,u ...

  3. Spring MVC报错:The request sent by the client was syntactically incorrect ()

    原因: 1.参数名称不一致 2.参数类型不一致

  4. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  5. Spring Boot报错 MultipartException The temporary upload...

    Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...

  6. iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容

    iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...

  7. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  8. Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property

    Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...

  9. 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';

    后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...

随机推荐

  1. 线性代数之行列式的C#研究实现

    最近学习机器学习 才发现以前数学没有学好 开始从线性代数开始学起 读完行列式一章写了些C#的代码学习一下. 直接上C#代码: using System; using System.Collection ...

  2. python paramiko模块 用密钥传输

    VM_129_78_suse:/home/remote_paramiko # cat remote.py #!/usr/bin/env python import paramiko linux_cmd ...

  3. 《java.util.concurrent 包源码阅读》10 线程池系列之AbstractExecutorService

    AbstractExecutorService对ExecutorService的执行任务类型的方法提供了一个默认实现.这些方法包括submit,invokeAny和InvokeAll. 注意的是来自E ...

  4. 《java.util.concurrent 包源码阅读》20 DelayQueue

    DelayQueue有序存储Delayed类型或者子类型的对象,没当从队列中取走元素时,需要等待延迟耗完才会返回该对象. 所谓Delayed类型,因为需要比较,所以继承了Comparable接口: p ...

  5. 状态压缩dp第一题

    标签: ACM 题目: Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; ...

  6. [全排列]--A Number Puzzle

    标签: ACM Lele 最近上课的时候都很无聊,所以他发明了一个数字游戏来打发时间. 这个游戏是这样的,首先,他拿出几张纸片,分别写上0到9之间的任意数字(可重复写某个数字),然后,他叫同学随便写两 ...

  7. 单词接龙dfs洛谷

    题目传送门:https://www.luogu.org/problem/show?pid=1019#sub 典型的爆搜,每次更新最大龙长度即可 搜索每个字符串编号,与已经连接好的字符串进行比较,以此往 ...

  8. Django学习(2)数据宝库

    数据库是一所大宝库,藏着各种宝贝.一个没有数据库的网站,功能有限.在Django中,支持的数据库有以下四种: SQLite3 MySQL PostgreSQL Oracle 其中SQLite3为Dja ...

  9. CS Round#49 C Max Substring

    Max Substring Time limit: 1000 msMemory limit: 256 MB   You are given a string S. Find a string T th ...

  10. JDBC详解系列(二)之加载驱动

    ---[来自我的CSDN博客](http://blog.csdn.net/weixin_37139197/article/details/78838091)---   在JDBC详解系列(一)之流程中 ...