- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含两个实体的 OneToMany
数据模型。一台机器包含许多特性。
问题: 当我尝试获取数据库的完整数据时,程序陷入无限循环。查看 JSON 结果 - 数据一直重复......
[{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":[{"name":null,"description":"CHARACTER2","type":0,"value":0,"machine":{"name":"Neue Machine","description":"Description der neuen machine","characteristics":
等等……
我真的不知道为什么会这样。以编程方式插入数据似乎工作正常!当前数据由以下代码行产生:
@RequestMapping(value = "/machine", method = RequestMethod.GET)
Collection<Machine> readMachines(){
Machine machine = new Machine("Neue Machine", "Description der neuen machine");
//Set<Characteristic> newCharacter = new HashSet<Characteristic>();
for(int i = 0; i < 6; i++){
machine.addCharacteristic(new Characteristic("CHARACTER" + Integer.toString(i),0,0));
}
machineRepository.save(machine);
return (Collection<Machine>) machineRepository.findAll();
}
问题:无限循环从何而来?
数据库模型
机器:
创建语句:
CREATE TABLE `machine` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(45) NOT NULL,
`description` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8
实体:
@Entity
@Table(name = "characteristic")
public class Characteristic {
private int characteristic_id;
private String name;
private String description;
private int type;
private int value;
private Machine machine;
@ManyToOne
@JoinColumn(name="machine_id")
public Machine getMachine(){
return machine;
}
public void setMachine(Machine machine){
this.machine = machine;
}
public Characteristic() {}
public Characteristic(String description, int type, int value) {
this.description = description;
this.type = type;
this.value = value;
}
public Characteristic(int characteristic_id, String description, int type, int value) {
this.characteristic_id = characteristic_id;
this.description = description;
this.type = type;
this.value = value;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="characteristic_id")
public int getCharacteristic_Id() {
return characteristic_id;
}
public void setCharacteristic_Id(int characteristic_id) {
this.characteristic_id = characteristic_id;
}
@Column(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Column(name="type")
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
@Column(name="value")
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
特点:
创建语句:
CREATE TABLE `characteristic` (
`characteristic_id` int(11) NOT NULL AUTO_INCREMENT,
`machine_id` int(11) NOT NULL DEFAULT '0',
`name` varchar(45) DEFAULT NULL,
`description` varchar(45) DEFAULT NULL,
`type` int(11) NOT NULL,
`value` int(11) DEFAULT NULL,
PRIMARY KEY (`characteristic_id`),
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1
实体:
@Entity
@Table(name = "machine")
public class Machine {
private int machine_id;
private String name;
private String description;
private Set<Characteristic> characteristics;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "machine", cascade = CascadeType.ALL)
public Set<Characteristic> getCharacteristics() {
return characteristics;
}
public void setCharacteristics(Set<Characteristic> characteristics){
this.characteristics = characteristics;
}
public Machine(){}
public Machine(String name, String description){
this.name = name;
this.description = description;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
public int getId() {
return machine_id;
}
public void setId(int machine_id) {
this.machine_id = machine_id;
}
@Column(name="name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public void addCharacteristic(Characteristic characteristic){
if(this.characteristics == null){
this.characteristics = new HashSet<Characteristic>();
}
characteristic.setMachine(this);
this.characteristics.add(characteristic);
}
}
CrudRepository:
public interface MachineRepository extends CrudRepository<Machine, Integer>{}
最佳答案
在您的代码中,您返回了 Machine
的集合。此类对 Characteristic
具有一对多依赖性。 Characteristic
类对Machine
具有多对一 依赖性。
当 Machine
对象被序列化时,它会查看依赖项 Characteristic
,最后会回顾 Machyne
,依此类推。除非您排除引用同一对象的属性,否则无法序列化这些循环依赖项。您应该排除一对多 或多对一 属性。
关于mysql - CrudRepository : findAll() stucks in infinite loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38072574/
Weblogic 10.3.6 管理控制台有两个与卡住线程时间配置相关的参数。 其中一个:Servers -> Some_Server -> Configuration -> Tuning 具有参数:
我正在使用 lift-json 将 JSON 字符串反序列化为 Scala 案例类。我正在解析的 JSON 有一个共同的结构:数据、成功和错误字段,其中数据包含有趣的位。我已经创建了一个 APIRes
我偶尔会做一名 VBA 程序员,只是为了好玩(不是我的工作)。 我在 MS Excel 2010 中有一系列 VBA 模块。无法弄清楚我做错了什么。这个例程奏效了,然后我改变了一些东西,它就不再起作用
给定以下 C 代码: struct list_element { struct list_element * next; }; typedef struct list_element list
我正在尝试创建一个类似乒乓球的游戏,并且我已经开始实现一些有关 Racket 运动的代码。桨本身的运动一切正常。然而,当我突然改变桨的方向时(更具体地说,当我立即从向上移动桨切换到向下移动桨时,反之亦
我是第一次在网站上手工编码(主要是打印设计师)。我试图只使用 HTML 和 CSS,因为我没有时间深入研究任何 Javascript,而且我真的很想了解我在使用什么。因此,我的主要内容设置在图像网格中
我正在制作一款类似 rogue 的游戏,我正在使用网格内的随机游走来形成“洞穴”系统。然而,我提出的随机游走会卡住——尤其是当游走者靠近网格边缘并且被“洞”包围时。 这不是我在我的项目中使用的确切代码
我在将我的分支推送到远程存储库时遇到问题。 Git 返回一个错误:错误:dst refspec refs/heads/XXX 匹配多个。 当我运行 git ls-remote 时,它只显示一个 XXX
我在终止集群中的命名空间时遇到问题,它在命名空间 JSON 中显示了许多参数。我点击了这个链接 https://medium.com/@craignewtondev/how-to-fix-kubern
首先,我为非描述性标题道歉。因为我不知道实际发生了什么,所以我不能让它更具体。 现在我的问题。我已经为 99 Haskell problems 的问题 23 实现了以下片段,应该随机选择n列表中的项目
尝试解决 eqb_trans 我陷入困境: Theorem eqb_trans : forall n m p, n =? m = true -> m =? p = true -> n =?
我曾经想在Grails中记录sql查询,所以我在数据源中添加了 logSql = true 并在log4j中 trace 'org.hibernate.type' debug 'org.hiberna
我在一个相互碰撞的世界中有几个球。世界各地都有静墙。 有时,它们最终会处于沿同一路径向上/向下或向左/向右移动的位置(垂直于墙壁的运动?) 有什么简单的方法可以检测到这一点,然后在任一方向上对其进行一
我有两个 MySQL 服务器,它们在同一组复制上运行。设置已通过以下步骤完成: 第一台服务器是有大量数据的生产服务器。 我将它设置为只读并转储数据,然后在后备 MySQL 服务器上恢复它 恢复后,我执
编辑:我意识到我的OP中的代码又长又难读。我用 4 行代码突出显示了这个问题。 char **t = {"Hello", "World"}; char **a = t; ++(a[0]); print
我试图将图像上传到服务器,但不知何故代码停在了 FileInputStream 行。不知道为什么,我不知道如何调试或检查它。这是我的源代码: public class CreateSetcardSt
规范:Ubuntu 13.04、Python 3.3.1 一般背景:Python 初学者; 特定问题的背景:我已经精疲力竭地试图解决这个问题,而且我知道,除了它对学习 Python 的指导值(valu
我创建了这个递归脚本,用于检查您所在的地址,然后检查另一个文件层次结构(如果您所在的文件夹也存在于该位置)。例如,假设您在 somerandomsite.com/example/folder/fold
我制作了视频来向您展示确切的问题(向上)。我有一个卡片动画。第一个动画是当您加载页面时,这些卡片会自动飞入。 .card{ animation: startup .5s ease-in-out .2s
简介: 我研究了 blocking TCP server 的 MSDN 示例和 blocking TCP client . 鉴于修改这些示例以创建简单的聊天应用程序,我想尝试一些简单的事情。 首先,我
我是一名优秀的程序员,十分优秀!