Question: I know that the following code will delete the record with id = 5 from database:

```
 Query query = session.createQuery("delete from Class where id = 5");
 query.executeUpdate();

```

But before i delete it, need to save this record's data in a variable.
So I want to select id = 5, and after some code, I delete it.
It's not efficient if i use two distinct query for them. Because in this way we search database for this item two times. 

```
query = session.createQuery("from Class where id = 5");
//somecode
query = session.createQuery("delete Class where id = 5");
...

```

So i need a more efficient way to do this, and do it better.

Answer: 
No need to create query to delete a record.

```
query = session.createQuery("from Class where id = 5");
List list=query.list();
if(list.size()!=0)
 {
   ClassName obj = (ClassName)list.get(0);
   session.delete(obj);
  }

```
Hibernate has a `Session.delete()` method. Use it if you already have a reference to the entity to remove. No need for a query. 

This would also apply the potential cascades configured on associations, which a delete query does not.