[Persistence, JBoss/CMP, Hibernate, Database] - OnetoMany - cascade all
by trouby
Hey,
I think I have a very basic confusion regarding cascade,
I have the following simple relationship:
| public class message {
|
| private Set<Comment> comments;
|
| @OneToMany(mappedBy = "message", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
| public Set<MessageComment> getComments() {
| return comments;
| }
|
| //set...
| }
|
And
| private Message message;
|
| @ManyToOne(optional=false)
| public Message getMessage() {
| return message;
| }
|
| //setter
|
I'm trying to persist a new comment by:
| //assuming a message with id 1 exists in db
| Message m = entityManager.find(Message.class,new Long(1));
| Comment c = new Comment();
| c.setMessage(m);
| m.getComments.add(c);
| entityManager.merge(m);
|
I don't want to persist the comment directly but through the message,
if 'getComments' is cascaded with ALL, shouldn't the new comments get persisted when em.merge(m) is invoked?
Thanks,
Asaf.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4116101#4116101
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4116101
17 years