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

解决方法:在回答类中的问题类属性上加注解:@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. [最短路][部分转] P1073 最优贸易

    题目描述 C 国有 n 个大城市和 m 条道路,每条道路连接这 n 个城市中的某两个城市.任意两个 城市之间最多只有一条道路直接相连.这 m 条道路中有一部分为单向通行的道路,一部分 为双向通行的道路 ...

  2. laravel MethodNotAllowedHttpException错误一个原因

    前两天在写api的时候,出现一个之前都没有碰到过的问题,如图 可以说提示信息是很不友好了,然后打开错误日志,发现报了一个MethodNotAllowedHttpException这样的错误,这样错误我 ...

  3. SQL---存储过程---存储过程编写案例

    存储过程的创建和调用演示 1.不带参数的存储过程的创建 create procedure PRO_With_No_Param as Begin --begin可省略 select * from sc ...

  4. 深入了解Android蓝牙Bluetooth——《进阶篇》

    在 [深入了解Android蓝牙Bluetooth--<基础篇>](http://blog.csdn.net/androidstarjack/article/details/6046846 ...

  5. 从a标签传值中文乱码解决

    <% out.print(new String(request.getParameter("a标签的参数").getBytes("iso8859-1"), ...

  6. jquery类数组结构学习笔记

    大家都知道我们使用$()产生的jquery对象可以使用下标去获取对应下标的元素. 举个栗子,一个页面有5个div标签,我们使用$("div")去获取到这些元素,然后我们就可以使用$ ...

  7. ##1.Centos7环境准备-- openstack pike

    ##1.Centos7环境准备 openstack pike 安装 目录汇总 http://www.cnblogs.com/elvi/p/7613861.html ##.Centos7环境准备 #Ce ...

  8. P1197 [JSOI2008]星球大战

    题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过特殊的以太隧道 ...

  9. 04.redis集群+SSM整合使用

    redis集群+SSM整合使用 首先是创建redis-cluster文件夹: 因为redis最少需要6个节点(三主三从),为了更好的理解,我这里创建了两台虚拟机(192.168.0.109 192.1 ...

  10. mysqldump指定编码导出数据

    mysqldump指定编码导出数据 第一步,导出旧库 mysqldump --default-character-set=latin1 -uroot -pXXX --database db >  ...