I'm having the error and I'm not understanding why there is no code below although I know what he means.
Error
Org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before cleaning: com.domain.Car.motor -> com.domain.Motor
I was having this error in another method, when I reported session.flush () and session.clear () the error propagated to this method now, I would understand not to have Fill in the session.flush () and session.clear () code.
I am not using cascade because motor is not to be saved along with car, I want to save engine inside car
The error occurs in the criteria in the sample method SaveSend(Carro carro);
Example of the problem
@Entity
@Table(name="carro")
public class Carro implements Serializable {
@Id
private Long codigo;
private String nome;
@ManyToOne(targetEntity=Motor.class)
@JoinColumn(name="codigoMotor", referencedColumnName = "codigoMotor")
private Motor motor;
// get and set
}
@Entity
@Table(name="motor")
public class Motor implements Serializable {
@Id
private Long codigoMotor;
private String nome;
// get and set
}
public void salvar() {
carro.setMotor(getMotor);
dao.salvar(carro); // Saving the car Ok;
depoisSalvar(carro);
}
public void depoisSalvar(carro) {
salvarVenda(carro);
}
// Saving the sale
public void salvarVenda(Carro carro) {
// Before saving, go to DAO to find the buyer
Criteria cri = getSession().createCriteria(Vendedor.class);
cri.add(Restrictions.eq("carro.codigo", carro.getCodigo()));
return cri.list(); // Aqui acontece o erro....
dao.salvar();
}