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

解决方法:在回答类中的问题类属性上加注解:@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. Java 中实现方法重试的一种机制

    有这样一个需求,当调用某个方法抛出异常,比如通过 HttpClient 调用远程接口时由于网络原因报 TimeOut 异常:或者所请求的接口返回类似于"处理中"这样的信息,需要重复 ...

  2. iOS开发经验总结

    总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; ...

  3. 使用canvas绘制时钟 (http://heeroluo.net/Article/Detail/95)

    准备工作 在HTML中指定一个区域放置时钟: <div id="clock" style="position: relative;"></di ...

  4. Struts2-052验证脚本

    下面分享一下Struts2-052验证的python脚本 #-*- coding:utf-8 -*- import requests url_list_path ="/home/d0ll4r ...

  5. js获取url地址栏参数

    前端开发中经常会遇到需要获取url地址栏参数问题 方法如下: function getQueryStringByName(name){ var src = "www.baidu.com?na ...

  6. Maven引入jar的总结

    Overview:显示maven项目的一些基本信息 Dependencies:添加jar包的页面 Plugins:添加maven插件的页面.比如tomcat-maven-plugin等 Reporti ...

  7. hibernate第一天

    首先介绍一下javaEE开发的三层架构 Web层    也被称为表现层    它是表现层的一个设计模型:也就是大家常用的MVC开发模式 Service层   它是和需求相关的 DAO层   它只和数据 ...

  8. # openVPN+LDAP AD认证,组权限管理

    # openVPN+LDAP AD认证,组权限管理 原创内容http://www.cnblogs.com/elvi/p/7661178.html # openVPN+LDAP AD认证,组权限管理 # ...

  9. CCF-201509-2-日期计算

    问题描述 试题编号: 201509-2 试题名称: 日期计算 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 给定一个年份y和一个整数d,问这一年的第d天是几月几日? 注意闰年 ...

  10. Relax信息学题库须知

    Relax信息学题库须知 1.本题库于2017.10.15开始建设(建设中),私聊我便可成为题库管理员,关注我即可成为题库成员.我的QQ:2026503022,微信:dy060207. 2.本题库的建 ...