spring mvc报错,数据库查询无限死循环
进行查询的陷入了无限死循环,原因是问题类中包含了回答,回答类中包含了问题,进入了无限死循环
解决方法:在回答类中的问题类属性上加注解:@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报错,数据库查询无限死循环的更多相关文章
- 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 ...
- 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 ...
- Spring MVC报错:The request sent by the client was syntactically incorrect ()
原因: 1.参数名称不一致 2.参数类型不一致
- 解决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 ...
- Spring Boot报错 MultipartException The temporary upload...
Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...
- iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容
iis 7上发布mvc报错:403.14-Forbidden Web 服务器被配置为不列出此目录的内容 提示里面的解决方法是: 如果不希望启用目录浏览,请确保配置了默认文档并且该文件存在. 使用 II ...
- Spring Boot 报错记录
Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...
- 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 ...
- 【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 ...
随机推荐
- Spring JDBC 示例
在使用普通的 JDBC 数据库时,就会很麻烦的写不必要的代码来处理异常,打开和关闭数据库连接等.但 Spring JDBC 框架负责所有的低层细节,从开始打开连接,准备和执行 SQL 语句,处理异常, ...
- 在PostgreSQL自定义一个“优雅”的type
是的,又是我,不要脸的又来混经验了.我们知道PostgreSQL是一个高度可扩展的数据库,这次我聊聊如何在PostgreSQL里创建一个优雅的type,如何理解优雅?大概就是不仅仅是type本身,其它 ...
- 六、VueJs 填坑日记之初识*.Vue文件
上一篇博文中,我们将接口的地址通过webpack代理到了本地,解决了跨域的问题.在之前的文章中,我们一直对项目进行配置,并没有真正的切入正题,可能很多人还不明白我们要做什么?那么今天,我们就要开写代码 ...
- Unity3D高性能战争迷雾实现
效果图 先上效果图吧,这是为了吸引到你们的ヽ(。◕‿◕。)ノ゚ 战争迷雾效果演示图 战争调试界面演示图 由于是gif录制,为了压缩图片,帧率有点低,实际运行时,参数调整好是不会像这样一卡一顿的. 战争 ...
- iOS面试题最全梳理
OC的理解与特性 OC作为一门面向对象的语言,自然具有面向对象的语言特性:封装.继承.多态.它既具有静态语言的特性(如C++),又有动态语言的效率(动态绑定.动态加载等).总体来讲,OC确实是一门不错 ...
- javascript文档节点
创建文本节点 document.createTextNode() 创建新文本节点,该方法接收一个参数,即要插入节点中的文本信息. <script> //创建一个div节点 var elem ...
- (译)ABP之依赖注入
原文地址:https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection 什么是依赖注入 传统方式的问题 解决方案 构造函数注入 ...
- mysql 双机热备注意事项
上一篇文章已经介绍过 主从复制, 本文对主从复制只是简单描述,如对主从复制不清楚的,可以先看上一篇文章 主从复制 一:介绍 mysql版本:5.7.20 第一个主服服务器ip:192. ...
- 通过YUM升级centOS内核,以便安装docker
安装Docker要满足一定的条件,对于cents系统,要求必须是64位,并且内核版本是3.10以上. 如果你的centos操作系统内核低于3.10,需要升级到这个版本以上,才能安装docker. 第一 ...
- TensorFlow MNIST(手写识别 softmax)实例运行
TensorFlow MNIST(手写识别 softmax)实例运行 首先要有编译环境,并且已经正确的编译安装,关于环境配置参考:http://www.cnblogs.com/dyufei/p/802 ...