Hello All,
Is is possible to escape the redundant select-before-insert during saving an entity with OneToMany collection?
For example:
Code:
@Entity
public class Messages {
...
@OneToMany(fetch = FetchType.EAGER, mappedBy = "pk.message",cascade = {CascadeType.ALL})
private List<MessageRecepients> recepients = new LinkedList<MessageRecepients>();
}
For example the call session.save(message) for a new message with 2 recepients generates the next sqls:
Code:
Hibernate: insert into messages (...) values (...)
Hibernate: select messagerec_.message_id, ... from message_recepients messagerec_ where messagerec_.message_id=? and messagerec_.user_id=?
Hibernate: select messagerec_.message_id, ... from message_recepients messagerec_ where messagerec_.message_id=? and messagerec_.user_id=?
Hibernate: insert into message_recepients (message_id, ...) values (?, ...)
Hibernate: insert into message_recepients (message_id, ...) values (?, ...)
If I remove CascadeType.ALL and save "recepients" collections separately no any select statements are occured.
PS: The "message_recepients" table's PK is composite - (message_id,user_id).
Thanks,
Alex