New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem querying from collection with multiple logical operations in where part, then one of them contains "any()". #670

Closed
pvlptr opened this Issue Feb 20, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@pvlptr

pvlptr commented Feb 20, 2014

Problem querying with QueryDSL collections with multiple logical operations in where part, then one of them contains "any()".

Then I a executing this test it fails (I expect it should pass):

 ....
import com.mysema.query.collections.CollQueryFactory.*;
import com.mysema.query.types.Predicate;
import static org.hamcrest.Matchers.*;
....
@Test
public void testSearchCollection() {
    Document doc1 = new Document();
    doc1.setId(1L);       
    doc1.getMeshThesaurusTerms().add("x");

    Document doc2 = new Document();
    doc2.setId(2L);

    Document doc3 = new Document();
    doc3.setId(3L);

    List<Document> expResult;        
    Predicate crit;

    QDocument qDoc = QDocument.document;

    crit = qDoc.id.eq(3L);        
    expResult = from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc); 
    assertThat(expResult, containsInAnyOrder(doc3)); //ok       

    crit = qDoc.meshThesaurusTerms.any().eq("x");
    expResult = from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc); 
    assertThat(expResult, containsInAnyOrder(doc1)); //ok

    crit = qDoc.meshThesaurusTerms.any().eq("x").or(qDoc.id.eq(3L));
    expResult =  from(qDoc, doc1, doc2, doc3).where(crit).list(qDoc);
    assertThat(expResult, containsInAnyOrder(doc1, doc3)); //fails, expResult contains only doc1, but should contain doc1 and doc3!
}

Entity:

@Entity
@Table(name = "doc_documents")
public class Document {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @ElementCollection(fetch = FetchType.LAZY)
    @CollectionTable(name = "doc_document_mesh_thes_terms",
        joinColumns =
            @JoinColumn(name = "document_id"))
    @Column(name = "thesaurus_term", nullable = false, length = FieldLength.STRING_MED)
    @OrderColumn(name = "idx")
    private List<String> meshThesaurusTerms = new ArrayList<>();
    ….
}    

I am using JPA (Hibrenate v4.1.7) and Query DSL(v3.2.3)

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Feb 22, 2014

Member

What kind of query does the from method create? Are you querying with Querydsl JPA or Querydsl Collections? The title is a bit misleading.

Member

timowest commented Feb 22, 2014

What kind of query does the from method create? Are you querying with Querydsl JPA or Querydsl Collections? The title is a bit misleading.

@pvlptr

This comment has been minimized.

Show comment
Hide comment
@pvlptr

pvlptr Feb 22, 2014

I am querying from collection with QueryDsl collections.

pvlptr commented Feb 22, 2014

I am querying from collection with QueryDsl collections.

@timowest timowest added the bug label Feb 22, 2014

timowest added a commit that referenced this issue Mar 21, 2014

@timowest timowest added the fixed label Mar 21, 2014

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Mar 24, 2014

Member

Released in 3.3.2

Member

timowest commented Mar 24, 2014

Released in 3.3.2

@timowest timowest closed this Mar 24, 2014

@timowest timowest added this to the 3.3.2 milestone Apr 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment