This is my code to insert into two tables. But it gives me an error "Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1"
Session session = sessionFactory.getCurrentSession();
ProfileDTO profile = new ProfileDTO();
profile.setCustomerID(1);
profile.setProfileName(profileName);
profile.setProfileType(profileType);
profile.setRecordId(9);
session.save(profile);
int profileID = profile.getRecordId();
CustomerMeasurementsDTO measurement = new CustomerMeasurementsDTO();
String ids[] = profileidsString.split(",");
String vals[] = profilevalsString.split(",");
for (int i = 0; i < ids.length ; i++){
measurement.setMeasurementId(ids[i]);
measurement.setMeasurementValue(vals[i]);
measurement.setCustMeasurementsProfileId(profileID);
session.save(measurement);
};
When executed, It gives this for logging purpose.
Hibernate:
/* insert com.domain.CustomerMeasurementsDTO
*/ insert
into
cust_measurements
(cust_measurements_record_id, last_modified, measurement_id, measurement_value, measurement_record_id)
values
(?, ?, ?, ?, ?)
Hibernate:
/* update
com.domain.CustomerMeasurementsDTO */ update
cust_measurements
set
cust_measurements_record_id=?,
last_modified=?,
measurement_id=?,
measurement_value=?
where
measurement_record_id=?
I want it to make an insert query again, while its trying to update. Please help me where I'm wrong.