In simple java code if i want to delete city all i need to do is:
city = null;
but in hibernate this is not enough. You need to delete all the reference to city, so you can not write just java code without the need to be aware to the ORM layer.
I thought to solve it by forbid to use in set null and obligant the developer to use in DAO for operations like this.
but in hibernate this is not enough. You need to delete all the reference to city, so you can not write just java code without the need to be aware to the ORM layer."
Actually I would say that is a Java thing and not a ORM or Database thing.
If I have references to an object on the heap, say three references, then doing just city=null will not delete the city object, you still have two other references that will keep that object from being deleted, aka garbage collected. So you would still have to do the same thing with or without Hibernate.
You solve it the same way you would solve it without ORM. You set all the references to null through code if you want to make sure the object is available for garbage collection.
Which class it is in depends on where it makes most sense for that particular problem. Maybe it is a DAO maybe it is in some Business Logic class, I can't say that one is better than the other, because it is use case driven.