Hi,

I have a JPA data model that I'm trying to use with CXF's SearchContext.

In order to constrain the searching that can be done I'm trying to use a search class that is not a JPA entity (and that just contains a subset of the JPA fields).
Q1. Is this the right way to solve this problem?
Q2. How should I get it to work?

Details:

I have a "User" interface that the "User_JpaImpl" entity class derives from.
I also have a "UserFilter" class that just has two properties (username & enabled) - the User interface also has getters and setters for these properties, but there is no relationship between UserFilter and User (or User_JpaImpl).

My best attempt so far looks like this:
SearchCondition<UserFilter> sc = searchContext.getCondition(UserFilter.class);
        JPACriteriaQueryVisitor<UserFilter, User_JpaImpl> visitor =
new JPACriteriaQueryVisitor<>(entityManager, UserFilter.class, User_JpaImpl.class);
        searchCondition.accept(visitor);

        TypedQuery<User_JpaImpl> query = visitor.getTypedQuery();
        List<? extends User> result = query.getResultList();

This throws an exception in accept because of this:
        if (builder == null) {
            builder = em.getCriteriaBuilder();
            cq = builder.createQuery(queryClass);
            root = cq.from(tClass);
            predStack.push(new ArrayList<Predicate>());
        }

tClass is UserFilter.class, which is not known to JPA and thus cannot be used as root (cq.from(tClass) throws IllegalArgumentException).


All I want to do is limit the set of fields that can be queried, if this is the wrong approach I'm happy to swap it for another.

Thanks.

Jim

Reply via email to