Reputation: 2856
I have a very slow code here. All it does is that it colleting all rows with a specific entity column.
List<Data> slectedData = dataService.findByJobNameOrderByDateTime(selectJob.getValue().getName());
List<Data> deleteThese = slectedData.subList(firstIndex - 1, lastIndex);
for (List<Data> deleteTheseLists : Lists.partition(deleteThese, 2000)) {
dataService.deleteInBatch(deleteTheseLists);
}
Then I create a sub list
and I want to delete that sublist.
But the sublist can be very large and then dataService.deleteInBatch(deleteTheseLists);
takes alot of time.
The entity
class Data
looks like this:
@Entity
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Data {
// ID
@Id
@GeneratedValue
private long id;
// Made by
private String jobName;
private String calibrationName;
@Column(columnDefinition = "DATETIME(3)")
private LocalDateTime dateTime;
// Analog input
private float sa0;
private float sa1;
private float sa1d;
}
And I want to delete on dateTime
. Is that possible in Spring Boot JPA?
Because I can't delete on id
because the id
key is not correct indexed in the database because sometimes the database takes long time to insert data, and sometimes it goes fast. So it's a very unsecure way to delete entities
in JPA
.
Upvotes: 1
Views: 9284