I have a situation in my application that i want to save new records. I am using Crudrepository save() method. As we all know what save() will do save if record is not there and update if its found.
But i want to restric the Update operation. Like if the record is already available neither update not save that record.
Let say below is our Entity class which have composite key. and based on composite key we want to do this operation.
Entity class
@Entity
@IdClass(PrescriptionKey.class)
public class Prescription implements Serializable{
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="prescription_id")
private int prescriptionId;
@Id
@Column(name="dose_id")
private int doseId;
@Id
@Column(name="med_id")
private int medId;
//Setter Getters
}
Composite key class
public class PrescriptionKey implements Serializable {
private int doseId;
private int medId;
//Setter Getter
}
Let say every time the data which comes for save operation contains new data along with the old which was saved already. Now we want to perform only save for the new data.