I have a problem in Hibernate when updating child table When a duplicate record comes the parent table record gets updated but a new column gets inserted in child table, where as the child table also needs to be updated and not inserted. Using session.saveOrUpdate(storeObject)
Have tried cascade presist, SaveOrUpdate, but the issue is not resolved
@Entity
@Table(name = "Garage")
public class Garage {
@OneToMany( mappedBy = "garage")
@Cascade(CascadeType.PERSIST)
public Set<Car> getCars() {
return cars;
}
}
@Entity
@Table(name="Car", uniqueConstraints=@UniqueConstraint(columnNames={"GarageId"}))
public class Car {
private Garage garage;
@ManyToOne(optional=false)
@JoinColumn(name="GarageId")
public Garage getGarage() {
return garage;
}
}