I need to choose dynamically which parameters should be in query output. Is there any way to do something like that: For example I have Entity User with name, surname, address, age. In one case I want to choose only name, in other sername, age and address. And e.t.c Answer You can create interfaces to represent a View like the
Tag: spring-data-jpa
I am trying to create an API using SpringBoot but I don’t know how to handle json request/response
I am new to Java and Spring boot. I am creating a new API. Using postman I am sending a request body which contains request header and request payload. Then I have a controller which handles the request with the help of RequestPayload class. (And a service and dao file but I am sure those are ok.) Kindly let me
Should Spring Boot Data JPA automatically create EntityManagerFactory bean?
Should Spring Boot Data JPA automatically create EntityManagerFactory bean? I have added a table using Liquibase called Fred to my code, and now I wish to add JPA support for this. Upon adding: I get I understood that this bean should be created by spring. Can anyone explain when spring creates this bean for me? If it doesn’t, why not?
Spring jpa database connection for native query
I have a spring application that have to connect to a sql server db. There are no @Entity class and there ate no @Repository because the tables and the columns of the tables are unknown to the application. I have created a class and used an entity manager to execute queries, but I’m not sure this is the best choice
Is CSRF token require for Rest API in Spring boot
I am creating a Rest API using Spring boot on back-end and React js on frontend . I have a login form on React , should I enable csrf token on login/register form or not . After user logs in that user will get access token which I will store in memory in React and Refresh token in http only
Post request transform int field to string automatically
I’m doing a dummy app of a hostpital. The problem I’m having is that, I’m trying to verify that when a Patient is created, the fields passed are of the correct type, but whenever I POST an Int in a String field, it doesn’t fail and just transform the Int to String. The field I’m trying to make fail is
INTERVAL expression in Spring Data JPA Native Query
I have Spring JPA. I have a query like this in sql oracle: I have a CrudRepository in which I use the above query in native mode, like this: I get ORA-00933: Passing myValue as integer between quotes I get ORA-01867 Passing myValue as integer without quotes I get ORA-00933 How to do it? Answer See comments on question, there
How to search in parent entity scope when using spring boot data rest
Now I know how to findBySomething on root level entity. Let’s say I have a one to many relation of class -> student I can now students/search/findByName?name=Tom But it will give me Tom in all classes. Can I do something like classes/1/students/search/findByName?name=Tom It gives error right now. Answer in StudentController in StudentService in StudentRepository (I use mongoDB; if u use
Spring data JPA: Three entities ManyToMany relations, query duplicate result with findById
User.java UserRole.java RolePermission.java JDK:17 SpringBoot:2.7.4 findById and findBy are also generate different structure SQL. findById uses left outer Join. findByName uses subquery. the user only have one role, the role have three permissions. if use findByUsername It will return the user info correctly. If I use findById, the same role repeat three times。 } code : https://github.com/shuanshuan/demo-questions Answer While fetching
Hikari CP DB connection not release in Async block
I am using Spring Boot application which has API controller to generate reports . The actual service function is wrapped around @Async annotation and function makes DB calls and generates the csv reports . I am also using Hikari CP for connection pool management and JPA + QueryDSL for forming select queries . I am seeing strange issue in that