-->
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.  [ 2 posts ] 
Author Message
 Post subject: Why Cascade.Persist not working?
PostPosted: Tue Jul 26, 2011 11:55 pm 
Newbie

Joined: Tue May 31, 2011 8:02 pm
Posts: 2
So i Have two entities:

Horario and Disciplina with a @ManyToMany bidirectional relationship, and Disciplina is the owner:
Code:
@ManyToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER )
   public List<Horario> getHorarios() {
      return horarios;
   }


and when i try doing this:
PS: disciplina is an instance of Disciplina and horarios is a List<Horario> type
Code:
Transaction tx = session.beginTransaction();
disciplina.setHorarios(horarios);
session.save(disciplina);
tx.commit();


It just doenst work, but when I try
Code:
session.persist(disciplina)
instead, it does work!



So, why Cascade.Persist works with session.persist but it doesn't with session.save? it shows the following error when I try with save:

Code:
  [color=#FF0000]object references an unsaved transient instance - save the transient instance before flushing: br.com.matricula.entidades.Horario[/color]


I'm newbie with this excellent but complex framework, so I'm trying to understand why cascade persist doesn't work with save().

Thanks!


Top
 Profile  
 
 Post subject: Re: Why Cascade.Persist not working?
PostPosted: Wed Jul 27, 2011 3:31 am 
Newbie

Joined: Tue Feb 06, 2007 11:59 am
Posts: 4
There is a CascadeType.SAVE_UPDATE for saving.


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

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.