Hi,
I just started using Hibernate with JPA 2 but I'm still having some problems understanding the fundamentals.
Let's say I have 2 Classes:
@Entity
class User
@Entity
class Permission
I connect the two via a mapping-table "user_permission" which references the user_id and permission_id from the main-tables.
Whenever I want to delete a Permission from a User I cannot delete the Permission from the User-object because
then a Row would be deleted from the "permission" table.
Instead I have to delete it from the mapping-table "user_permission".
What would be the best way to do this in Hibernate/JPA?
Are there any annotations available for such a Usecase or do I have to use a Query from the EnityManager here:
Code:
em.createQuery("DELETE FROM user_permission WHERE user_id = :userid AND permission_id = :permission_id")
Thanks in advance, getagrip