Spring – Multiple Spring Data modules found, entering strict repository configuration mode

Sorry for answering too late, but I think answers that present already does not explain the actual, deep reason why is it happening. Let me explain everything in order to let you understand the guts (be ready, it will be quite long and comprehensive). If you are looking for simple solution, go to the bottom … Read more

Spring JPA native query with Projection gives “ConverterNotFoundException”

with spring data you can cut the middle-man and simply define public interface IdsOnly { Integer getId(); String getOtherId(); } and use a native query like; @Query(value = “Id, OtherId from TestTable where CreationDate > ?1 and Type in (?2)”, nativeQuery = true) public Collection<IdsOnly> findEntriesAfterDate(Date creationDate, List<Integer> types); check out https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections

Spring Boot TestContainers Mapped port can only be obtained after the container is started

You are trying to use PostgresSQLContainer as JUnit ClassRule but your usage of @ExtendWith seems to indicate that you are using JUnit 5 / Jupiter which does not support JUnit 4 rules. Use the JUnit 5 integration of Testcontainers instead: https://www.testcontainers.org/test_framework_integration/junit_5/

JPA/SpringBoot Repository for database view (not table)

1. Create View with native SQL in the database, create or replace view hunters_summary as select em.id as emp_id, hh.id as hh_id from employee em inner join employee_type et on em.employee_type_id = et.id inner join head_hunter hh on hh.id = em.head_hunter_id; 2. Map that, View to an ‘Immutable Entity’ package inc.manpower.domain; import org.hibernate.annotations.Immutable; import org.hibernate.annotations.Subselect; … Read more

Set default page size for JPA Pageable Object

If you are talking about a Spring Data PagingAndSortingRepository you can set the default page size by using the @PageableDefault on a Controller method as follows: public String listClients(@ModelAttribute FilterForm form, Model model, WebRequest request, @PageableDefault(sort = { “surname”, “forename”, “address.town” }, value = 50) Pageable pageable) { } Or you can configure a global … Read more

How to use LIMIT in spring within sql query?

LIMIT is not part of JPQL. The mechanism available in current release version (1.6.0.RELEASE as of the time of writing) is pagination: interface PersonRepository extends Repository<Person, Long> { @Query(“…”) List<Person> findLimited(…, Pageable pageable); } This can then be used as follows: repository.findLimited(…, new PageRequest(0, 10)); This will return the first ten results of the query … Read more

Spring-Data JPA: save new entity referencing existing one

I had a similar issue where I was trying to save an new entity object with an already saved entity object inside. What I did was implemented Persistable< T > and implemented isNew() accordingly. public class MyEntity implements Persistable<Long> { public boolean isNew() { return null == getId() && subEntity.getId() == null; } Or you … Read more

Spring Webflux + JPA: Reactive Repositories are not supported by JPA

If you want all the benefits of reactive, async / non-blocking, you’ll need to make the whole stack async / non-blocking. JDBC is indeed inherently a blocking API, so you can’t build a fully reactive / non-blocking app if you need to access the database through JDBC. But you still you need relational database then … Read more