Hibernate delete objects on cascade

后端 未结 2 1404
余生分开走
余生分开走 2021-01-19 11:26

I\'m sligthly confused as to how the cascade=\"delete\" works. I defined the mapping in the following way in the City mapping file:



        
2条回答
  •  死守一世寂寞
    2021-01-19 11:54

    1. If you delete a city, then all clients will be deleted as well. If you delete a client, the city will be left alone.

    2. session.delete() can't be called with a HQL query. You must pass it one city to delete.

    Alternatively, you can use session.createSQLQuery() to create a delete statement. That allows you to delete many cities in one go. The drawback with this method is that you must delete the clients yourself and flush the cache (Hibernate makes no attempt to understand what your query might mean).

提交回复
热议问题