我有规格:
final String text = "%text%";
final Specifications<PersonEntity> spec = Specifications.where(
(root, query, builder) -> builder.like(builder.lower(root.join(PersonEntity_.addresses, JoinType.LEFT).get(AddressEntity_.addressLine1)), text)
).or(
(root, query, builder) -> builder.like(builder.lower(root.join(PersonEntity_.addresses, JoinType.LEFT).get(AddressEntity_.addressLine2)), text)
).or(
(root, query, builder) -> builder.like(builder.lower(root.join(PersonEntity_.addresses, JoinType.LEFT).get(AddressEntity_.city)), text)
)
使用后:
personRepository.findAll(spec);
在日志中,我看到,JPA创建了一个查询,它连接地址三次而不是一次。
如何编写一个只能连接一次地址的规范?
答案 0 :(得分:14)
我把它改为:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.BorderPane?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" />
现在,它只加入一次。