Announcement Announcement Module
Collapse
No announcement yet.
spring data jpa custom query Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring data jpa custom query

    Hi

    I am using the spring data jpa API, everything work fine as for the moment I am making query to get entities.
    All methods (findA(...), findBy..(...)) return entities.

    I need to query the number of users by date :
    select birthday, count(id) from user group by birthday

    How can I perform this query with spring data jpa ?
    I need to receive a collection of dates with the number of user.

    In case I can't do that with spring data jpa I have another question ?
    How can I get a criteria builder from the LocalContainerEntityManagerFactoryBean ?

    is It ok to do localContainerEntityManagerFactoryBean.getObject. getCriteriaBuilder()

    Regards

  • #2
    Find a solution

    Here is my solution, not nice but works

    Code:
    JPAQuery query = new JPAQuery(entityManager);
    
    query.from(...);
    query.where(...);
    query.groupBy(...);
    query.orderBy(user.dateCreated.asc());
    
    return query.list(ConstructorExpression.create(UserTO.class, user.dateCreated, user.count()));
    In am using JPAQuery from querydsl

    It will be nice que be able to get a JPAQuery from the QueryDslJpaRepository.

    Regards

    Comment

    Working...
    X