2015-04-04 13 views
9

varsayalım ben varlıkları (getters/ayarlayıcılar ve kısaca geçilmiştir çeşitli ayrıntılar) vardır: Ben boş üzerinde gerçekleştirilmelidir sahip belirli bir Müşteri için tüm Kuponlar almak isteyenBahar veri sorgulama

@Entity 
class Customer{ 
    ... 
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer") 
    Collection<Coupon> coupons; 
} 

@Entity 
class Coupon{ 
    ... 
    @Temporal(value = TemporalType.TIMESTAMP) 
    private Date usedOn; 

    @ManyToOne(fetch = FetchType.LAZY) 
    @NotNull 
    Customer customer; 
} 

. docs

@Repository 
public interface CouponRepository extends CrudRepository<Coupon, Long> { 
    Collection<Coupon> findByCustomerAndUsedOnIsNull(Customer); 
} 

açıklandığı gibi, ama bu, bir derleyici hata Syntax error, insert "... VariableDeclaratorId" to complete FormalParameterList üzerinde yol açar gibi, 'ettik başarısız CouponRepository bir yöntem tanımlamışlardır.

cevap

7

Benim hatam, doğru tanımı

olduğunu
@Repository 
public interface CouponRepository extends CrudRepository<Coupon, Long> { 
    Collection<Coupon> findByCustomerAndUsedOnIsNull(Customer customer); 
} 

Sadece parametre ismini kaçırdım :-(

10

bu şekilde yöntemini değiştirmeyi deneyin (Customer.id varsayarak bir uzun):

Collection<Coupon> findByCustomer_IdAndUsedOnIsNull(Long customerId);

sonra böyle kullanın:

repo.findByCustomer_IdAndUsedOnIsNull(customer.getId());

İlgili konular