Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring JPA具有给定标识符的多行_Spring_Database_Hibernate_Cascade - Fatal编程技术网

Spring JPA具有给定标识符的多行

Spring JPA具有给定标识符的多行,spring,database,hibernate,cascade,Spring,Database,Hibernate,Cascade,对于这个问题,我已经尝试了其他解决方案,可惜问题仍然存在。这就是错误: org.hibernate.hibernateeexception:找到多个具有给定标识符的行:1,用于类:CO3102.hw2.domain.records 在org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 在o

对于这个问题,我已经尝试了其他解决方案,可惜问题仍然存在。这就是错误:

org.hibernate.hibernateeexception:找到多个具有给定标识符的行:1,用于类:CO3102.hw2.domain.records 在org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:86)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 在org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:143)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 在org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:2122)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 在org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:692)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 在org.hibernate.type.EntityType.resolve(EntityType.java:434)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final] 在org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:154)~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]

我一直在做的是: 我有一个记录类,包含名称、疫苗id、剂量等。我正在将一个疫苗行保存到这个疫苗id部分中,但现在当我添加更多用户时,我会出现上述错误。我在这里尝试了许多解决方案,但它们对我不起作用,所以如果有人能帮助我,请。这是我的记录课。其他解决方案谈到添加fetch.type=lazy,我已经这样做了,但仍然会出现错误

记录类

@OneToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name ="Vaccine_vaccineID")
private Vaccine vaccine;
疫苗类

@Id
String vaccineID;
String Name;
VaccineType type;
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "vaccine")
private records record;
我会再次解释这个问题,所以有两种可能的疫苗(a,b),它们的ID为1和2。很明显,我希望多个用户拥有相同的疫苗id。我这样做是否有误?我是否应该在此处保存一个数字1,而不是实际保存该行


如果有人能为我提供这个问题的解决方案,我将非常感激。杰夫

你可能想要实现的是多对一的关系。 请尝试以下操作:

记录

@ManyToOne(fetch = FetchType.LAZY, optional = true)
@JoinColumn(name ="Vaccine_vaccineID")
private Vaccine vaccine;
疫苗

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "vaccine")
private List<Record> records;
@OneToMany(cascade=CascadeType.ALL,orphaneremovation=true,mappedBy=“疫苗”)
私人名单记录;

谢谢您,先生!你救了我谢谢:)