I have a nativeQuery in my DAO layer inside my Spring Boot app. Basically, I’ passing three parameters, like so: I would like to have different WHERE statements executing depending on value of companyName, something like this: Or Answer Use boolean logic:
Tag: spring-boot
What is the best way to update data in database using Native Query
Here if one of data in rule object is null apart from rule_id(As it’s necessary) this query will fail, so instead I can format string for each value in Rule object and concat them excluding which has null value in Rule object but is there any better way to do this? Because if there are 100s of columns then this
Populate DTO using query with JOIN
I have this main Product table: Additional table for storing categories that should be returned as List: Additional table for storing Payment Methods that should be returned as List: I want to return a result like this: I tried this: What is the proper way to populate this DTO? Answer If, as indicated in your comments, you need query your
Will Converting my H2 memory database to a SQL database mess up any actual logic on my project? Spring Boot
I am currently using the H2 memory database for my website. Everything is working so far but to progress my teacher said to transition from the h2 database to a SQL since it resets everytime you restart the program. I was wondering if I transitioned, would it mess up any of my logic / code. I know I would have
SQL query returns void in Spring Boot application but does not in H2
Good evening, I’m sure I’m missing something about how to write queries in a Spring Boot application and would appreciate correction. SQL query in h2-console: SELECT customer_id FROM customers WHERE …
Flyway don’t clean database correctly, and execute migration files two times
I’m using flyway for migration database, as well I use FlywayTest for my integration tests, but When I create a test using : I get this error : If you not : This comes from FlywayTestExecutionListener.class but it migrate the database again. Why flyway do this, and how can stop this. More details The problem is not happen when I
JPA batch_size property does not work for native query
I’m trying to make a bulk insert with a native query. I’ve added batch_size property to the application.properties file But in the logs, I see that every insert processed separately. Is it possible to apply batching to native query? Answer If the entities use GenerationType.IDENTITY identifier generator, hibernate will silently disable batch inserts/updates. Please find the following link for the
How to use JPA to save datetime of SQL to fix: “Conversion failed when converting date and/or time from character string.”
I got a very frustrated problem.. I cannot use the JPA save function to store correct datetime object of SQL, I got the following error: There is my code: In Controller: In Entity: Many thanks!! Answer I recomend you to use LocalDateTime of modern java.time. JPA automatically convert LocalDateTime into database datetime. To get current datetime use LocalDateTime.now(). You can
One to One Mapping Spring boot
Hello everyone in advance I have a problem with my one to one connection when I try to log in to the “user” I get this error what i need is a one to one connection that does not have to be persistent that means a user can have a player but does not have to have it and the
JPA Criteria Builder query with inner SELECT statement
I need to create the below SQL join condition using JPA criteria builder, Below is the entity class and JPA query builder. I am able to build the query with join condition but cannot create the inner SELECT query. How can i create a inner select query for join clause? Requirement description: The below is the input table and output