Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Criteria API and Regexp
Criteria API and Regexp [message #1445317] Wed, 15 October 2014 09:16 Go to next message
Francesco Gatti Gómez is currently offline Francesco Gatti GómezFriend
Messages: 3
Registered: October 2014
Junior Member
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 14:34 Go to previous messageGo to next message
Francesco Gatti Gómez is currently offline Francesco Gatti GómezFriend
Messages: 3
Registered: October 2014
Junior Member
This looks impossible right? Sad
Re: Criteria API and Regexp [message #1448844 is a reply to message #1447572] Mon, 20 October 2014 14:20 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1380
Registered: July 2009
Senior Member
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 08:27 Go to previous message
PANKAJ AGRAWAL is currently offline PANKAJ AGRAWALFriend
Messages: 1
Registered: July 2015
Junior Member
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: Mon Mar 08 13:35:38 GMT 2021

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

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

Back to the top