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.
Because in this way we search database for this item two times.