paulvi / TODO

0 stars 0 forks source link

composed query for Spring Data JPA #14

Open paulvi opened 8 years ago

paulvi commented 8 years ago

A lot of business entities are big classes with 20-30 fields, so making finders for every one, and then finders for all possible pairs, and then ... would be just wrong approach.

Instead there have been used composing of JPA query and executing it with

.getHibernateService().findList(queryString, parameterMap)

How should this be within Repository?

That is while Repository is interface, some for methods an implementation should be provided.

paulvi commented 8 years ago

From https://github.com/spring-projects/spring-data-examples

jpa\example\src\main\java\example\springdata\jpa\custom\UserRepositoryImpl.java

/**
 * GitHub\spring-data-examples\jpa\example\src\main\java\example\springdata\jpa\custom\UserRepositoryImpl.java
 * @author Paul Verest
 *
 */
public class TnpTrainTicketRepositoryImpl implements TnpTrainTicketRepositoryCustom{

    @PersistenceContext private EntityManager em;

    /**
     * Configure the entity manager to be used.
     * 
     * @param em the {@link EntityManager} to set.
     */
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }

    @Override
    public Page<TnpTrainTicket> findAsTnpTrainTicket(TnpTrainTicket con, Pageable pageable) {
        String qlString = "";
        // query string composing logic
        Query query = em.createQuery(qlString);
        return null;
    }
}