spring-repositories

Return type of JPA Repository 'getOne(id)' Method

眉间皱痕 提交于 2021-01-29 11:09:53
问题 I have the following Spring boot service for an object of type Report - @Service public class ReportService { @Autowired private ReportRepository reportRepository; @Autowired private UserRepository userRepository; /*get all reports */ public List<Report> getAllReports(){ return reportRepository.findAll(); } /*get a single report */ public Report getReport(Long id){ return reportRepository.getOne(id); } //other similar methods.... } The problem arises while retrieving a single Report. If a

Spring-boot application. Failed to load ApplicationContext in JUnit tests

我怕爱的太早我们不能终老 提交于 2021-01-29 08:34:44
问题 Failed to load ApplicationContext in conditional scenarios The issue is the 2 repository tests-classes will fail to load the ApplicationContext for the FIRST test-case of that test class IF any other test is run before the class. Project on Github "fix-unit-tests" branch I've got a series of JUnit component tests for a spring-boot maven application using an Mongodb Embedded database. 2 of the test-classes runs unit tests on the 2 spring-repositories. BUT, the test-classes ran by themselves

Find entity by exact matching in collection

牧云@^-^@ 提交于 2021-01-27 05:01:08
问题 I have entity like this: @Getter @Setter @Entity public class Conversation extends AbstractEntity{ @ElementCollection @Column(name = "user_id", nullable = false) @CollectionTable(name = "conversation_user", joinColumns = @JoinColumn(name = "conversation_id", nullable = false)) private List<String> usersIds; } Is possible to find conversation entity by spring's repository by exact matching of user ids? For instance I have these entities: id | user_ids ------------------------------------------

OneToMany with query dsl and dto pattern problem

ぐ巨炮叔叔 提交于 2020-08-06 07:09:11
问题 i have below entities Cart(id, cartNumber) - one Cart has many CartDetail CartDetail(id, quantity, total, cartId, productId) Product(id, name) - one Product has many CartDetail i also have corresponding DTO classes now using QueryDSL with DTO pattern i need to find out cart by id with following fields cartId, cartNumber, cartDetails(quantity, total, productName) currently this i am doing like below JPQLQuery<CartDto> jpqlQuery = query.select(new QCartDto(cart.id, cart.cartNumber, cart

How to query JPA LocalDateTime field with a LocalDate value?

杀马特。学长 韩版系。学妹 提交于 2020-07-09 11:52:25
问题 I search for a way to get a list of Objects created on a certain LocalDateTime date saved in the Postgresql database in a field of type TIMESTAMPTZ. To do so, I tried to use JpaRepository: List<Object> findByCreationDate(LocalDate date); But I get the error: java.lang.IllegalArgumentException: Parameter value [2020-12-12] did not match expected type [java.time.LocalDateTime (n/a)] I also tried writing the query myself with the same result. The solutions I thought about so far : To get all the

How to query LocalDateTime with LocalDate?

被刻印的时光 ゝ 提交于 2020-06-16 04:56:30
问题 I've got a class which contains an atttribute of java.time.LocalDateTime type. public class MyClass{ // ... private LocalDateTime fecha; // ... } I'm using Spring Data repositories. What I want to accomplish is to query entities according to a date: @Service public interface IRepository extends CrudRepository<MyClass, UUID> { // ... public void deleteByFecha(LocalDate fecha); // ... } But this does not work, as an exception is thrown: org.springframework.dao.InvalidDataAccessApiUsageException

RedisCustomConversions using Redis Repository

我的未来我决定 提交于 2020-06-01 05:08:49
问题 Is it possible to use custom Redis converters with Spring-Data Repository? I see the example in https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis.hashmappers.jackson2 but I get the following error when I try it. @Bean definition illegally overridden by existing bean definition: Root bean: class [org.springframework.data.redis.core.convert.RedisCustomConversions] My code to register the converter is @Bean fun redisCustomConversions():RedisCustomConversions {

@Query named parameters for MongoDb Spring repository

…衆ロ難τιáo~ 提交于 2020-03-23 06:22:07
问题 Is it possible to use named parameters for a @Query method in a mongodb repository, just like we can do with a jpa repository (http://docs.spring.io/spring-data/jpa/docs/1.4.3.RELEASE/reference/html/jpa.repositories.html section 2.3.5)? As an example, I would like to use the following code: @Query("{'store' : :store, 'app' : :app }") List<T> findByStoreAndApp(@Param("store") String store, @Param("app") String app); instead of: @Query("{'store' : ?0, 'app' : ?1 }") List<T> findByStoreAndApp

Spring LdapRepository returns no results while Spring Security works

懵懂的女人 提交于 2020-01-05 07:33:30
问题 My Problem I am using an LdapRepository to get user information from an Ldap server. This Ldap server is also queried by Spring Security to authenticate user. My issue is, that Spring Security is able to find and identify users, while I'm unable to find users through my LdapRepository, using the same LdapContextSource. Querying the LdapRepository in any way does not return results ( null or empty Lists). What I have tried Using the ldapsearch tool directly - Works Using LdapQuery instead of