Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Write A "Count By" Method Name Query In Spring Data

Tags:

spring-data

So I know that I can write an interface like the one below and Spring Data will automatically generate the necessary database access stuff for me. Now what I'd like to do is add a new method name that will count the number of entities that match a set of criteria.

public interface EventRegistrationRepository extends JpaRepository<EventRegistration, String>
{    
    List<EventRegistration> findByUser_EmailAddress(String email);

    int countByEvent_Code(String eventCode);
}

As of now the countBy method causes this error:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property count found for type com.brazencareerist.brazenconnect.model.relational.EventRegistration

What's the proper syntax for what I'm trying to do here?

like image 842
HappyCoder86 Avatar asked Jun 11 '13 15:06

HappyCoder86


1 Answers

This works as expected as of the just released Spring Data JPA 1.4.0.M1.

like image 105
Oliver Drotbohm Avatar answered Jan 04 '23 08:01

Oliver Drotbohm