I have an object -
@Entity
public class myObject{
public MySecondObject objA;
public MySecondObject objB;
...
}
I dont have any instance of it but I want to delete all the rows in db that have
fieldA == thirdObj
I have an instance of thirdOBJ but no instance of myobjects.
it is possible to do it with native sql. but than I will need to use the auto assigned id of thirdobj - to compare in the db.
Is there a more elegant way than this?
try {
session.beginTransaction();
session.createQuery("delete from MyObject where fieldA = " +
thirdObject.getID()).executeUpdate();
session.getTransaction().commit();
savedSuccessfully = true;
} catch (HibernateException e) {
session.getTransaction().rollback();
savedSuccessfully = false;
} finally {
session.close();
}
return savedSuccessfully;