0

When I use JPA with MySQL, the below query works fine. But when I use it with ObjectDB, it throws the exception below.

public Friendship getFriendship(String username) {
    CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
    CriteriaQuery<Friendship> query = criteriaBuilder.createQuery(Friendship.class);
    Root<Friendship> root = query.from(Friendship.class); 
    Path<String> path = root.<String>get("username");
    query.where(criteriaBuilder.equal(path, username));
    return em.createQuery(query).getSingleResult();
}

The error from the browser

 type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: com.objectdb.o._PersistenceException: Unexpected query token 'FROM' (SELECT is expected)
root cause

com.objectdb.o._PersistenceException: Unexpected query token 'FROM' (SELECT is expected)
root cause

com.objectdb.o.UserException: Unexpected query token 'FROM' (SELECT is expected)
ObjectDB
  • 1,312
  • 8
  • 9
kasavbere
  • 5,873
  • 14
  • 49
  • 72
  • It's EclipseLink. But I thought JPA, which is the java interface, was supposed to be implementation blind? Does the implementation matter? – kasavbere Oct 03 '12 at 15:56
  • CORRECTION: For the `objectdb` version I am using `com.objectdb.jpa.Provider`. For the `MySQL` version I am using `org.eclipse.persistence.jpa.PersistenceProvider`. Apparently, they are both `EclipseLink`. – kasavbere Oct 03 '12 at 15:59
  • Try adding `criteriaBuilder.select(root);` before executing query. – d1e Oct 03 '12 at 19:18
  • There is a `criteriaBuilder.selectCase(root);` option. But when I add it, there is no difference. – kasavbere Oct 03 '12 at 19:27
  • Oops, my bad. Add query.select(root); I guess. – d1e Oct 03 '12 at 20:37
  • @kasavbere So does this mean that the query did NOT work in mysql after all? – carbontax Oct 04 '12 at 12:55

1 Answers1

0

As noted above correctly (and as shown by the error message) - a select is missing.

A valid JPQL query must include SELECT, otherwise the query is incomplete.

Some JPA implementations extend the standard JPQL by supporting queries with no SELECT.

ObjectDB
  • 1,312
  • 8
  • 9