Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » javax.persistence.criteria.Predicate cannot be passed across methods(criteria API find by Predicate )
javax.persistence.criteria.Predicate cannot be passed across methods [message #1721789] Sat, 30 January 2016 09:54 Go to next message
Eclipse UserFriend
The following code snippet will recreate the problem, the Predicate cannot be passed to findByType2. If we call entityManager.createQuery(criteriaQuery.select(root).where(p)).getSingleResult();
in the findByType() directly, it would work fine.
Any ideas?

public MyObject findByType(final MyObject.Type type)
{
    final EntityManager entityManager = getEntityManager();
    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<MyObject> criteriaQuery = builder
        .createQuery(MyObject.class);
    final Root<MyObject> root = criteriaQuery.from(MyObject.class);

    final Predicate p = builder.equal(
        root.<MyObject.Type>get(MyObject_.type), type);

    return findByType2(builder, criteriaQuery, p);
  }
  
  public MyObject findByType2(final CriteriaBuilder builder,
      final CriteriaQuery<MyObject> criteriaQuery,
      final Predicate p)
  {
    final EntityManager entityManager = getEntityManager();
    final Root<MyObject> root = criteriaQuery.from(MyObject.class);

    return entityManager.createQuery(
        criteriaQuery.select(root).where(
            p)).getSingleResult();
  }
Re: javax.persistence.criteria.Predicate cannot be passed across methods [message #1721936 is a reply to message #1721789] Mon, 01 February 2016 12:43 Go to previous messageGo to next message
Eclipse UserFriend
Maybe explain what is going wrong when you execute this code, and show the code that works. You are creating two EntityManagers and two Roots, so I wouldn't expect the above code to work as you are selecting from a different root then you used to build your predicate.
Re: javax.persistence.criteria.Predicate cannot be passed across methods [message #1722701 is a reply to message #1721936] Mon, 08 February 2016 06:55 Go to previous message
Eclipse UserFriend
Thanks for your reply. I think I made a mistake to describe the problem. I created a new topic at https://www.eclipse.org/forums/index.php/m/1722700/#msg_1722700.
Could you please have a look and coach me the problem? thanks.
Previous Topic:Where is the Javadoc for JPA when using EclipseLink ?
Next Topic:A javax.persistence.NonUniqueResultException Problem with Criteria API
Goto Forum:
  


Current Time: Tue Jul 15 16:33:35 EDT 2025

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

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

Back to the top