2017-07-18 2 views
1

に適用されていません次のサービス:Hibernateのフィルターは、私は私のリポジトリにこの休止フィルタを持っているFindOne CRUD操作

@Service 
@Transactional(propagation = Propagation.REQUIRED) 
public class GroupServiceImpl implements GroupService { 

    @Autowired 
    GroupRepository groupRepository; 

    @Override 
    public Group findGroupById(long id) { 
    Group group = groupRepository.findById(id); 
    return group; 
    } 
} 

及びこれらのリポジトリ:

@RepositoryRestResource(exported = false) 
public interface AbstractGroupRepository<T extends AbstractGroup> 
    extends JpaRepository<T, Long>, QueryDslPredicateExecutor<T> { 

List<T> findByNameIgnoreCase(String name); 

List<T> findByNameAndTypeOrderByNameAsc(String name, String type); 

List<T> findByIdOrderByNameAsc(Long id); 

AbstractGroup findById(Long id); 

}

public interface GroupRepository 
    extends AbstractGroupRepository<Group>, GroupRepositoryExtras { 

List<Group> findByNameAndCustomerId(String name, Long customerId); 

Iterable<Group> findByCustomerIdAndTypeIn(Long id, List<String> types); 

Group findById(long id); 

} 

問題は、私はgroupRepositoryを使用するときにということです。 findById(id)フィルタが正しく適用されています。

私はCRUDコアクエリgroupRepositoryを使用しています。 findOne(id)アスペクトを処理した後でもフィルタが適用されないhibernateSession.enableFilter(GROUP_ACL).setParameter( "userId"、userId); Javaがフィルタを有効にしても、ログファイルはハイバネートクエリのフィルタのトレースを表示しません。

問題は.findOneでしかないようです。 findAllは正常に動作しています。

findOneメソッドにフィルタを適用できないというHibernateのドキュメントには何かがありますか?

+0

こんにちは@Cyrilはあなたがどんな解決策を見つけるでした。.. – Karthigeyan

答えて

1

CRUDRepositoryクラスへのアクセスをリッスンしました。それが最善の方法かどうかはわかりませんが、それが私の問題を解決します。

@Component 
@Aspect 
public class ACLFilterAspect { 
    private static final String GROUP_ACL = "groupACL"; 

    @Autowired 
    private EntityManager em; 

    @Before("||execution(* *(..)) && this(com.trendshift.kyn.pug.data.GroupRepository)" 
      + "||execution(* *(..)) && this(org.springframework.data.repository.CrudRepository)") 
+0

あなたは上記のコードを確認してくださいfindOne呼び出しにフィルタを追加され、私は次のコード@Before(「実行(*を追加しましたorg.springframework.data.repository.CrudRepository 。*(..))") まだ動かない。他に提案がありますか? – Karthigeyan

関連する問題