Spring Data JPA and Querydsl to fetch subset of columns using bean/constructor projection

Looks like custom repository implementation is the way to go for now until something similar available in spring data. I have gone through http://static.springsource.org/spring-data/data-jpa/docs/current/reference/html/repositories.html#repositories.custom-implementations Here is my implementation which works. However it would be good to have this method available directly in Spring-Data-JPA Step 1: Intermediate interface for shared behavior public interface CustomQueryDslJpaRepository <T, ID … Read more

JPQL Like Case Insensitive

You can use the concat operator: @Query(“select u from User u where lower(u.name) like lower(concat(‘%’, ?1,’%’))”) public List<User> findByNameFree(String name); or with a named parameter: @Query(“select u from User u where lower(u.name) like lower(concat(‘%’, :nameToFind,’%’))”) public List<User> findByNameFree(@Param(“nameToFind”) String name); (Tested with Spring Boot 1.4.3)

Lombok @Builder and JPA Default constructor

Updated Based on the feedback and John’s answer I have updated the answer to no longer use @Tolerate or @Data and instead we create accessors and mutators via @Getter and @Setter, create the default constructor via @NoArgsConstructor, and finally we create the all args constructor that the builder requires via @AllArgsConstructor. Since you want to … Read more

spring data jpa @query and pageable

You can use pagination with a native query. It is documented here: Spring Data JPA – Reference Documentation “You can however use native queries for pagination by specifying the count query yourself: Example 59. Declare native count queries for pagination at the query method using @Query“ public interface UserRepository extends JpaRepository<User, Long> { @Query(value = … Read more

%Like% Query in spring JpaRepository

The spring data JPA query needs the “%” chars as well as a space char following like in your query, as in @Query(“Select c from Registration c where c.place like %:place%”). Cf. http://docs.spring.io/spring-data/jpa/docs/current/reference/html. You may want to get rid of the @Queryannotation alltogether, as it seems to resemble the standard query (automatically implemented by the … Read more

Spring boot Hibernate error “Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set” when working with multiple data sources

I figure it out. Modify method entityManagerFactory for both Db2Configuration and OracleConfiguration to supply them with the information about hibernate dialect: for DB2 @Primary @Bean(name = “db2EntityManagerFactory”) public LocalContainerEntityManagerFactoryBean entityManagerFactory( EntityManagerFactoryBuilder builder , @Qualifier(“db2DataSource”) DataSource dataSource) { final HashMap<String, Object> hibernateProperties = new HashMap<String, Object>(); hibernateProperties.put(“hibernate.dialect”, “org.hibernate.dialect.DB2390Dialect”); return builder .dataSource(dataSource) .packages(“project.dataconfig.db2.entity”) .properties(hibernateProperties) .persistenceUnit(“db2persistanceunit”) .build(); } … Read more

How to configure Spring Data JPA using XML

If you want to configure Spring Data JPA by using XML configuration (and use the configuration described in the book), you have to follow these steps: Configure the data source bean. Configure the entity manager factory bean. Configure the transaction manager bean. Enable annotation driven transaction management. Configure Spring Spring Data JPA. The application context … Read more

Use abstract super class as parameter for Spring data repository

If you aren’t using table inheritance on the database side (e.g. super class table with descriminator column), AFAIK, and based off reading the JPA tutorial, this can’t be done (i.e. simply using @MappedSuperclass annotation for your abstract class) Mapped superclasses cannot be queried and cannot be used in EntityManager or Query operations. You must use … Read more

Spring data : CrudRepository’s save method and update

I wanted to know if the {save} method in CrudRepository do an update if it finds already the entry in the database The Spring documentation about it is not precise : Saves a given entity. Use the returned instance for further operations as the save operation might have changed the entity instance completely. But as … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)