我有一个Customer
实体:
@Entity
@Table(name = "customer")
@Data
public class Customer {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
private UUID id;
@Column(unique = true)
private String name;
@ManyToMany(cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
})
@JoinTable(name = "customer_system_mapping",
joinColumns = @JoinColumn(name = "customer_id"),
inverseJoinColumns = @JoinColumn(name = "system_id")
)
private List<System> systems;
public Customer() {}
public Customer(String name) {
this.name = name;
}
public Customer(UUID id,
String displayName
List<System> systems) {
this.id = id;
this.name = name;
this.systems = systems;
}
}
和System
实体:
@Entity
@Table(name = "system")
@Data
public class System {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
private UUID id;
private String name;
public System() {}
public System(UUID id, String name) {
this.id = id;
this.name = name;
}
}
(@data
注释来自Project Lombok并自动生成getter和setter)。
我还有一个CustomerRepository
(使用property expression根据id
的{{1}}属性进行查询:
System
我希望发生的是,调用findBySystems_id会使用@Repository
public interface CustomerRepository extends PagingAndSortingRepository<Customer, UUID>, JpaSpecificationExecutor<Customer> {
Page<Customer> findBySystems_id(UUID id, Pageable pageable);
}
System
返回映射到JoinTable
的所有客户。如果customer_system_mapping
的条目与Customer
匹配,则System
会有customer_system_mapping
。
这是JPA生成的SQL:
[customer_id, system_id]
这是SQL绑定的日志:
select
customer0_.id as id1_0_,
customer0_.name as name_5_0_
from
customer customer0_
left outer join
customer_system_mapping syst1_
on customer0_.id=syst1_.customer_id
left outer join
system syst2_
on syst1_.system_id=syst2_.id
where
syst2_.id = ? limit ?;
当我将生成的SQL代码和绑定参数复制/粘贴到MySQL中时,我得到一个结果(正确的行为)。但是当我致电binding parameter [1] as [BINARY] - [3023f335-5d28-4244-996b-286a5f5c3446]
时,我得不到任何结果。
答案 0 :(得分:0)
属性的第一个字母应为大写
Page<Customer> findBySystems_Id(UUID id, Pageable pageable);