Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Criteria API and Regexp
Criteria API and Regexp [message #1445317] Wed, 15 October 2014 05:16 Go to next message
Eclipse UserFriend
Hello,

I am trying to use EclipseLink RegExp expression with the Criteria API.

The problem is I'm using a framework (Vaadin's JPAContainer) that forces me to use predicates and with JpaCriteriaBuilder I can only get an expression.

This code should help understand:
            @Override
            public void filtersWillBeAdded(CriteriaBuilder criteriaBuilder, CriteriaQuery<?> query, List<Predicate> predicates) {
                    JpaCriteriaBuilder cb = (JpaCriteriaBuilder) criteriaBuilder;
                    Root<?> r = query.getRoots().iterator().next();
                    Expression exp = cb.fromExpression(cb.toExpression(r.get("field")).regexp(REGEXP));
                    // how can I cast the previous expression to a predicate so that I can add it to the list of predicates??
            }


Any help will be highly appreciated!! Thanks,

Francesco
Re: Criteria API and Regexp [message #1447572 is a reply to message #1445317] Sat, 18 October 2014 10:34 Go to previous messageGo to next message
Eclipse UserFriend
This looks impossible right? Sad
Re: Criteria API and Regexp [message #1448844 is a reply to message #1447572] Mon, 20 October 2014 10:20 Go to previous messageGo to next message
Eclipse UserFriend
EclipseLink's native expressions to not implement JPA's criteria framework. Think of the JPA framework as a wrapper over top of EclipseLink's query/expression framework. The code you have shown is unwrapping the JPA code to get at the underlying expression. When done, you need to add it to the EclipseLink query somehow, and most commonly, the EclipseLink query object is used and just wrapped in a JPA query rather than attempting to reuse the JPA criteria builder framework. It should be possible with something like :

  Metamodel model =  em.getMetamodel();
  Predicate predicate  =  cb.isTrue(new ExpressionImpl(model, ClassConstants.BOOLEAN, exp) );


Best Regards,
Chris
Re: Criteria API and Regexp [message #1701320 is a reply to message #1448844] Sat, 11 July 2015 04:27 Go to previous message
Eclipse UserFriend
Hi Chris,

I am running into this exact problem while trying to use REGEXP function through CriteriaAPI.

In your below statement, what's ClassConstants.BOOLEAN?

Predicate predicate = cb.isTrue(new ExpressionImpl(model, ClassConstants.BOOLEAN, exp) );
Previous Topic:EclipseLink and Nullable Parts composite key
Next Topic:Descriptor customizers not invoked
Goto Forum:
  


Current Time: Tue Jul 01 01:05:27 EDT 2025

Powered by FUDForum. Page generated in 0.03077 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top