An Implementation of Spring Boot With Spring Data JPA
Check out this tutorial on how to get started building a Spring Boot application with Spring Data JPA.
Join the DZone community and get the full member experience.Join For Free
This guide includes my interest in how you can handle complex CRUD operations such a simple way with Spring Data JPA and using native queries in case of needs.
In this tutorial, I am using the Oracle database along with Spring Data. Besides, it will be helpful if you have a server dependency for Weblogic.
You may also like: Using the Spring Data JPA
First, we should define our JNDI name in our Spring Boot Project’s application.properties file. We must pay attention to the JNDI name we define in our properties file. It must be the same within our Weblogic’s DataSources JNDI Name.
Then, in our
DataSourceConfig class, we have some configurations about our JNDI and we define which classes to scan under our project's package as domain objects.
Let’s assume we have a customer table in our database.
With its associated JPA Entity:
Our query would be like below if we want to get 1000 corporate customers that subscribed on a given date.
We can query our records with that SQL but we can also query like below in a simpler way and our codebase will be consistent with our
Now, we able to list our records like this.
Also, we will be able to implement general CRUD operations like below without extra effort.
I also try to sample a native query call and also how to call a stored procedure with Spring Data below.
If you need to call
Stored Procedure it is also similar to querying a table. We create our
Entity like a database table and
Repository class to call it.
I hope everything goes well, thanks a lot...
Opinions expressed by DZone contributors are their own.