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!