Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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
Java Hibernate更新:为什么Hibernate先删除对象,然后再插入对象_Java_Hibernate - Fatal编程技术网

Java Hibernate更新:为什么Hibernate先删除对象,然后再插入对象

Java Hibernate更新:为什么Hibernate先删除对象,然后再插入对象,java,hibernate,Java,Hibernate,我使用Hibernate作为我的项目的orm解决方案,我不知道发生了什么。 我有一个实体用户: @Entity @Table(name="users") public class User { @Id @GeneratedValue(strategy=GenerationType.AUTO) private long id; ... @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinTable(name =

我使用Hibernate作为我的项目的orm解决方案,我不知道发生了什么。 我有一个实体用户:

@Entity
@Table(name="users")
public class User {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
...

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(name = "users_projects", joinColumns = {
            @JoinColumn(name = "userid") 
            },
            inverseJoinColumns = {
            @JoinColumn(name = "projectid") 
            })
    private List<Project> projects;
... +getters and setters
}
只是一个假设:


您的实体在更新之前被检索和合并后已分离。实际上,hibernate还没有对集合的更改进行跟踪,因此会将其作为一个包进行管理

似乎您没有正确地合并。是否从子集合中删除了任何内容?此外,我建议您使用适当的
hashCode()
equals()
,如果可能,尝试使用
Set
而不是
List
。是的,这可能是您的合并问题。在更新前和更新后检查用户\u项目表,检查他们的组合值是否更改。此外,序列化所有实体。可能的重复项
Hibernate: select this_.code as code1_1_0_, this_.name as name2_1_0_ from country this_
Hibernate: insert into projects (besoins, countryCode, description, title) values (?, ?, ?, ?)
Hibernate: select last_insert_id()
Hibernate: update users set activated=?, email=?, lastError=?, password=?, profil_id =?, role=? where id=?
Hibernate: update profil set countryCode=?, countryName=?, description=?, firstname=?, lastName=?, phone=?, title=? where id=?
Hibernate: update projects set besoins=?, countryCode=?, description=?, title=? where id=?
Hibernate: update projects set besoins=?, countryCode=?, description=?, title=? where id=?
Hibernate: update projects set besoins=?, countryCode=?, description=?, title=? where id=?
Hibernate: update projects set besoins=?, countryCode=?, description=?, title=? where id=?
Hibernate: delete from users_projects where userid=?
Hibernate: insert into users_projects (userid, projectid) values (?, ?)
Hibernate: insert into users_projects (userid, projectid) values (?, ?)
Hibernate: insert into users_projects (userid, projectid) values (?, ?)
Hibernate: insert into users_projects (userid, projectid) values (?, ?)
Hibernate: insert into users_projects (userid, projectid) values (?, ?)