Fernando Mendez
Fernando Mendez

Reputation: 19

IN predicate with a list in JOOQ return just the first value

I have a simple select in JOOQ with IN(List) predicate, but the result of this query is just for the first element in the list.

        List<Integer> ids = context.select(TABLE1.ID).from(TABLE1).where(
                TABLE1.NAME.eq(name)).fetch().into(Integer.class);

        List<MyObject> myObjectList = context.selectFrom(TABLE2)
                .where(TABLE2.ID.in(ids))
                .fetch().into(MyObject.class);

Data samples

First query result-> List Ids={1,2,3,4}

TABLE2 content -> MyObject (1, A), MyObject (2, B), MyObject (3, C), MyObject(4, D) ........., MyObject(21, Z)

Second query result -> MyObject(1, A)

Upvotes: 0

Views: 610

Answers (1)

Fernando Mendez
Fernando Mendez

Reputation: 19

SOLVED

The problem was the first query syntax.

Field<Integer> ids = context.select(TABLE1.ID).from(TABLE1).where(
                TABLE1.NAME.eq(name)).asField();

List<MyObject> myObjectList = context.selectFrom(TABLE2)
                .where(TABLE2.ID.in(ids))
                .fetch().into(MyObject.class);

Upvotes: 1

Related Questions