Hi, I have problem since hibernate 4.1.8 with this exception
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [test.hibernate.TestPrepravkaOsobaSAdresou$Uvazek#2]
I have simple OneToMany association between two entities:
Code:
@Entity(name = "Ppv")
@Table(name = "PPV")
public static class Ppv {
@Id
Long ppvId;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "ppv")
Set<Uvazek> uvazeks = new HashSet<Uvazek>(0);
}
Code:
@Entity(name = "Uvazek")
@Table(name = "UVAZEK")
public static class Uvazek {
@Id
Long uvazekId;
@ManyToOne
@JoinColumn(name = "PPV_FXID")
Ppv ppv;
}
and test case where I have one Ppv and two Uvazek. When I load and detach Ppv, delete one Uvazek associated with loaded Ppv and merge Ppv I get an exception.
Code:
jdbcTemplate.execute("insert into PPV values(1)");
jdbcTemplate.execute("insert into UVAZEK values(2, 1)");
jdbcTemplate.execute("insert into UVAZEK values(3, 1)");
Ppv ppv = (Ppv) getSession().get(Ppv.class, 1l);
getSession().clear();
getSession().delete(getSession().get(Uvazek.class, 2l));
getSession().flush();
getSession().merge(ppv);
getSession().flush(); //cause exception
Hibernate during Ppv merge try to load deleted Uvazek. But Uvazek is deleted. Hibernate has information about it in org.hibernate.collection.internal.AbstractPersistentCollection.storedSnapshot on uvazeks set on detached Ppv. In previous version (<4.1.8) this works. In this simple example I can repair it by adding orphanRemoval=true on uvazeks set on Ppv and instead of deleting uvazek remove it from uvazeks set on Ppv.
So my question is: Is this hibernate bug or my bad practise?