我有以下实体:
@Entity
public class Customer extends BaseEntity {
private String firstname;
private String lastname;
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL)
private Set<Address> addresses;
...
@Entity
public class Address extends BaseEntity {
private String street;
private String houseNumber;
private String zipCode;
private String city;
@ManyToOne
private Customer customer;
...
Run Code Online (Sandbox Code Playgroud)
以下存储库接口类:
@Repository
public interface CustomerRepository extends CrudRepository<Customer, Long> {
@Query("select c from Customer c join c.addresses a where (a.city = :cityName)")
List<Customer> findByCity(@Param("cityName")String city);
}
Run Code Online (Sandbox Code Playgroud)
现在,我正在尝试运行以下集成测试,但它失败了,我绝对不知道为什么.不幸的是,我是Spring的初学者,我正在努力学习它;-)
@Test
public void testFindCustomerByCity() {
Customer …Run Code Online (Sandbox Code Playgroud)