Deleting objects

Report a typo

Imagine we have the following classes:

  • An entity class:

Java
public class Customer {
    private Long id;
    private String name;
    private String surname;
}
  • A repository class:

Java
public class CustomerRepository extends CrudRepository<Customer, Long> {
}
  • Also, we have an initialized repository.

You want to delete the Customer entity with the ID 42. How can you do it? Choose all possible options from the list below:

Java

A)

repository.deleteById(42L);

B)

repository.deleteAllById(42L);

C)

Customer customer = repository.findById(42L);
repository.delete(customer);

D)

Optional<Customer> customer = repository.findById(42L);
customer.ifPresent(repository::delete);
Select one or more options from the list
___

Create a free account to access the full topic