diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryCustom.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryCustom.java index 1881194..f4e0443 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryCustom.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryCustom.java @@ -11,4 +11,6 @@ package com.fjordtek.bookstore.model.auth; public interface UserRoleRepositoryCustom { UserRole findByCompositeId(Long userId, Long roleId); + + void deleteByCompositeId(Long userId, Long roleId); } \ No newline at end of file diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryImpl.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryImpl.java index 0cfcfda..2c232ab 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryImpl.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/auth/UserRoleRepositoryImpl.java @@ -4,6 +4,7 @@ package com.fjordtek.bookstore.model.auth; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; +import javax.persistence.Query; import javax.persistence.TypedQuery; import org.springframework.transaction.annotation.Transactional; @@ -45,4 +46,17 @@ public class UserRoleRepositoryImpl implements UserRoleRepositoryCustom { } } + @Override + public void deleteByCompositeId(Long userId, Long roleId) { + + Query query = entityManager.createQuery( + "DELETE FROM UserRole" + + " WHERE user_id = :user_id" + + " AND role_id = :role_id" + ); + query.setParameter("user_id", userId); + query.setParameter("role_id", roleId); + query.executeUpdate(); + } + } \ No newline at end of file