How to do a double join in criteria api?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
21 views
I have the following picture.

There are 3 tables: 5c234b476d080426225192.jpeg

And I have RequestDTO that is fed to the settings endpoint'and to provide a search of the Database by criteria.

So she looks DTO:
@Data @AllArgsConstructor @NoArgsConstructor @Accessors(chain = true) public class RequestAssuranceAccessLine { @Pattern(regexp = LINE_ID) private String lineId; @Min(0) @Max(31) private Integer ontId; private Technology technology; @Size(max = 50) private String ontSerialNumber; @ApiParam(allowEmptyValue = true) public RequestAssuranceAccessLine setLineId(String lineId) { this.lineId = lineId; return this; } @ApiParam(allowEmptyValue = true) public RequestAssuranceAccessLine setOntId(Integer ontId) { this.ontId = ontId; return this; } @ApiParam(allowEmptyValue = true) public RequestAssuranceAccessLine setTechnology(Technology technology) { this.technology = technology; return this; } @ApiParam(allowEmptyValue = true) public RequestAssuranceAccessLine setOntSerialNumber(String ontSerialNumber) { this.ontSerialNumber = ontSerialNumber; return this; } }


ontId and ontSerialNumber are in two different tables.

To get ontId, I'm doing the following JOIN using the criterion:
// Join and predicate ontId from Default NeProfile Optional.ofNullable(requestAssuranceAccessLine.getOntId()).ifPresent(ontId -> { Join joinedDefaultNeProfile = root.join("defaultNeProfile"); predicates.add(criteriaBuilder.equal(joinedDefaultNeProfile.get("ontId"), ontId)); } );


But in order for me to get ontSerialNumberhave to go into table B, and table B joint C.

How am I supposed to do if the current criteria looks like this:
public static Specification criteriaForAccessLine(RequestAssuranceAccessLine requestAssuranceAccessLine) { return (root, query, criteriaBuilder) -> { List predicates = new ArrayList<>(); // Predicate lineId Optional.ofNullable(requestAssuranceAccessLine.getLineId()).ifPresent(lineId -> predicates.add(criteriaBuilder.equal(root.get("lineId"), lineId))); // Join and predicate ontId from Default NeProfile Optional.ofNullable(requestAssuranceAccessLine.getOntId()).ifPresent(ontId -> { Join joinedDefaultNeProfile = root.join("defaultNeProfile"); predicates.add(criteriaBuilder.equal(joinedDefaultNeProfile.get("ontId"), ontId)); } ); // Predicate technology Optional.ofNullable(requestAssuranceAccessLine.getTechnology()).ifPresent(technology -> predicates.add(criteriaBuilder.equal(root.get("technology"), technology))); return criteriaBuilder.and(predicates.toArray(new Predicate[0])); }; }
by | 21 views

1 Answer

0 like 0 dislike
decided.

First going A <- B, then B <- C

// Join and predicate ontSerialNumber from Subscriber NeProfile Optional.ofNullable(requestAssuranceAccessLine.getOntSerialNumber()).ifPresent(ontSerialNumber -> { Join joinedDefaultNeProfile = root.join("defaultNeProfile"); Join joinedSubscriberNeProfile = joinedDefaultNeProfile.join("subscriberNeProfile"); predicates.add(criteriaBuilder.equal(joinedSubscriberNeProfile.get("ontSerialNumber"), ontSerialNumber)); } );
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked Mar 23, 2019 by KriegeR
110,608 questions
257,186 answers
0 comments
35,392 users