important java springboot concept
Hi java LinkedIn family, I share a new concept.
if you are creating multiple services in Spring Boot, JPA, Hibernate and your project has the same database and different schema then currently what you are doing...
Let us say I am imagining right now.
Project 1 has a Candidate Entity (table) and you create a separate repository for it.
Project 2 has the same Candidate Entity (table) and you create a separate repository or you call a native query in Project 2 to get data related to the Candidate table to shop data that you call with Rest Template or a native update query.
In the future, if you add a field [column] in the candidate entity [table]
Then you need to add the same field in both Project 1 and Project 2.
For this conflict, I have found a solution to create a separate common entity module and define all the required tables [entities] in it that will be used in the project
Example: Here I have created a CommonEnityModule
And define all needed entities
Now step 2) created project 2 hiring-portal and its pom add commonEnityModule dependency
Step 3) import all entities from the external commonEnityModule
And finally run the hiring-portal project.As expected, an exception occurred, see the screenshot below
Exception: Caused by: java.lang.IllegalArgumentException: No managed type: class com.entity.web.cm.entity.Users
In the next step, we need to scan the main application by adding a required annotation
@SpringBootApplication
@EnableJpaRepositories(basePackages = {"com.entity.web.cm.entity", "com.credex.hiring.portal.repository"})
@EntityScan("com.entity.web.cm.entity")
public class HiringPortal {}
Have fun launching your application successfully.