openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harald Wellmann (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (OPENJPA-2333) Problem with duplicated results in criteria
Date Mon, 25 Feb 2013 16:10:15 GMT

    [ https://issues.apache.org/jira/browse/OPENJPA-2333?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13585964#comment-13585964
] 

Harald Wellmann commented on OPENJPA-2333:
------------------------------------------

I don't think this is a bug. Joins are allowed to return duplicate results. This may not be
what you expect, but it's correct according to the specs.

See http://stackoverflow.com/questions/8199512/jpql-inner-join-without-duplicate-records

The equivalent JPQL query also returns 2 results:

    select p from Person p left join fetch p.dogs  where p.dogs.name = 'Fire'

If you change this to
   
   select p from Person p left join p.dogs d where d.name = 'Fire'

you get one result. You also get one result when you modify the criteria query like this:

        Join dogs = mainRoot.join("dogs", JoinType.INNER);
        Predicate predicate = criteriaBuilder.and(criteriaBuilder.equal(dogs.get("name"),
"Fire"));

This may be a bit confusing, but at least JPQL and Criteria yield the same results for equivalent
queries. OpenJPA does not seem to take more freedom than is granted by the spec.

By the way, it would have been helpful to include an executable test case or at least a link
to existing code in this issue. I got here via 
http://java.dzone.com/articles/easycriteria-20-%E2%80%93-jpa-criteria and had a look at the
tests in http://code.google.com/p/easy-criteria/source/browse/trunk/src/test/java/com/uaihebert/test/TestAbstract.java
                
> Problem with duplicated results in criteria
> -------------------------------------------
>
>                 Key: OPENJPA-2333
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2333
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.2.1
>         Environment: linux or windows
> jdk 6 or 7
> OpenJPA 2.2
>            Reporter: Hebert Coelho
>
> I have described the problem in here: http://openjpa.208410.n2.nabble.com/Problem-with-JPA-Criteria-td7582759.html#a7582764
> The code bellow brings duplicated results when it should only bring one result
>         CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
>         CriteriaQuery<Person> criteriaQuery = criteriaBuilder.createQuery(Person.class);
>         Root<Person> mainRoot = criteriaQuery.from(Person.class);
>         criteriaQuery.select(mainRoot);
>         mainRoot.join("dogs", JoinType.INNER);
>         Predicate predicate = criteriaBuilder.and(criteriaBuilder.equal(mainRoot.get("dogs").get("name"),
"Fire"));
>         criteriaQuery.where(predicate);
>         TypedQuery<Person> criteriaGeneratedQuery = em.createQuery(criteriaQuery);
>         System.err.println(criteriaGeneratedQuery.getResultList()); // brings two objects
instead one
> In the tested database, there is only one dog named Fire.
> If you need more information, just say it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message