-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: select-before-insert CascadeType.ALL
PostPosted: Mon Nov 24, 2008 5:54 am 
Newbie

Joined: Sun Nov 23, 2008 12:03 pm
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.