spring-repositories

spring-data-jpa @RestController @Repository Optional strange behavior

非 Y 不嫁゛ 提交于 2019-12-24 20:25:28
问题 My @RestController @GetMapping("/projects/{project_id}") public Project getProjectById(@PathVariable(value = "project_id") UUID projectId) { return projectRepository.findById(projectId).orElseThrow(Util.notFound(projectId)); } My projectRepository is @Repository public interface ProjectRepository extends PagingAndSortingRepository<Project, UUID> { } public class Util { static Supplier<ResourceNotFoundException> notFound(UUID msg) { log.error(msg + " not found"); return () -> new

Spring Boot - Create Generics Repositories

人盡茶涼 提交于 2019-12-24 19:57:37
问题 I have many services in my web application that do a classic CRUD operations, theses are Parameters section. In order to avoid creating for each entity class, a repository interface, I want to create a generic repository. I tried the code below but that only works if I have one controller. public class BaseController<T extends BaseEntity> { @Autowired protected JpaRepository<T, Integer> dao; } @RestController @RequestMapping("matieres") @Api(value = "Matieres", tags = {"Parametrages"}) public

Multiple LDAP repositories with Spring LDAP Repository

荒凉一梦 提交于 2019-12-21 06:22:19
问题 I would like to set more than one LDAP repositories with Spring LDAP. My aim is to create or update objects in all repositories at the same time. I use LdapRepository Spring interface and I think that isn't possible for now. I wonder if I can create my own LdapRepository extending the Spring one but I have no idea how to start. This my configuration : @Configuration @EnableLdapRepositories("com.xxx.repository.ldap") @PropertySource("classpath:ldap.properties") public class LdapConfiguration {

Using Spring @Procedure to call StoredProcedure without binding to a table

这一生的挚爱 提交于 2019-12-20 05:43:07
问题 I would like to know if it is possible to call a stored procedure without having to bind it to a Table/Model? In my case I have a stored procedure in the database that sends a mail. I would like to call this from Spring: public interface SendEmail extends org.springframework.data.repository.Repository<Email, Long> { @Procedure(procedureName = "send_email") void sendEmail(String sender, String recipient, String ccRecipient, String subject, String message); } The above code compiles fine and

Spring Security in conjuction with Spring repositories to secure and authenticate various parts of a website

江枫思渺然 提交于 2019-12-20 05:11:41
问题 I was looking for a concrete, serious and complete example on how to use Spring security in a Spring Boot application that uses Spring data repositories to access the database and therefore to query about registered users. I've seen that it's easily protected a range of webpages using Spring security by overriding the configure method, for example with the following options: http.authorizeRequests() .antMatchers("/", "/css/**", "/js/**", "/vendor/**", "/templates/**") .permitAll() .anyRequest

Spring JpaRepository findBy…In(Collection) returns union not intersection

帅比萌擦擦* 提交于 2019-12-11 16:05:44
问题 I have a query method in my JpaRepository Page<Course> findDistinctCourseByAttrsInAllIgnoreCase(Set<String> a, Pageable page); to find Course objects by their instance variable Set<String> attrs . Given a Set a with "foo" and "bar", I want to find Course s whose attrs contain BOTH "foo" and "bar", i.e. an intersection of Course s with "foo" and those with "bar". This method above returns a union. Is there a way to do this with JpaRepository queries or do I have to make multiple calls and find

Cassandra Repository is always using keyspace from application.properties file not from the extended class of AbstractCassandraConfiguration

主宰稳场 提交于 2019-12-11 12:38:08
问题 I have my data are on different keyspaces, i have more than one keyspace in a spring boot application, so i want my cassandra repositories to be configurable with different keyspaces each rather than having one keyspace in application level. In a spring project, i am looking something like a keyspace should be configurable at Repository level. Cassandra Repository is always using keyspace from application.properties file, Not working if i extend AbstractCassandraConfiguration class and

How to make a generic repository in Spring Boot that accepts an entity and few attributes and returns all the records based on the attributes?

橙三吉。 提交于 2019-12-11 10:05:13
问题 I want to make a generic repository that accepts the entity class and few attributes like start_date and end_date, etc and returns all the records in the table. To fetch the results for a single entity using repository I will need to write a custom query. I am not sure how would I write a Custom query in a generic way for any entity that is passed and filter according to the attributes. 回答1: Since you are using Spring Data JPA you can declare your own shared repository interface with your own

How to use JPA Repositories without Spring Boot

只愿长相守 提交于 2019-12-10 19:46:02
问题 I have an existing spring 4 project (mvc, jdbc etc) and I tried to port it to spring boot and I can't. (many dependencies troubles, no one can't explain how I can do that). But now I just want to use Spring Data JPA in existing project. That is a main pom dependencies: <properties> <jetty.version>9.3.5.v20151012</jetty.version> <spring.version>4.3.12.RELEASE</spring.version> <spring.boot.version>1.5.8.RELEASE</spring.boot.version> <spring.security.version>4.2.3.RELEASE</spring.security

How to get all results in one page using Spring Data Pagination

为君一笑 提交于 2019-12-08 14:50:30
问题 I want to get all the results in single page, I've tried with Pageable p = new PageRequest(1, Integer.MAX_VALUE); return customerRepository.findAll(p); Above is not working, is there any methods to achieve this? Seems like it cannot be achieved from custom query as asked here. 回答1: Your page request is incorrect because you are looking for results at the wrong page. It should be: new PageRequest(0, Integer.MAX_VALUE); First page for results is 0. Since you're returning all records, they are