Hi.
I noticed a strange behaviour when I'm trying to merge an Entity using the EntityManager.
First of all, the entities:
Code:
@Entity
public class Import implements Serializable {
...
@OneToMany(targetEntity = MicroAction.class, cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
private List<MicroAction> microActions;
...
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="microActionType",
discriminatorType=DiscriminatorType.STRING
)
@DiscriminatorValue("MicroAction")
public abstract class MicroAction implements Serializable{
...
The inheritance is working fine though, so I don't think it's related to the problem.
Speaking of the problem, here's what is happening when I merge an 'Import' into the database (using simply merge method of EntityManager).
Code:
2004 Query delete from Import_MicroAction where Import_id=1
2004 Query insert into Import_MicroAction (Import_id, microActions_id) values (1, 7)
2004 Query insert into Import_MicroAction (Import_id, microActions_id) values (1, 3)
2004 Query insert into Import_MicroAction (Import_id, microActions_id) values (1, 1)
2004 Query insert into Import_MicroAction (Import_id, microActions_id) values (1, 4)
2004 Query insert into Import_MicroAction (Import_id, microActions_id) values (1, 5)
2004 Query insert into Import_MicroAction (Import_id, microActions_id) values (1, 9)
2004 Query commit
This is the dump of mysql.
Basically, everything is persisted correctly, but why does Hibernate needs to first delete the Import_MicroAction row, can't he just add the missing rows, the ones that wasn't persisted yet?