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

No alt text provided for this image

Now step 2) created project 2 hiring-portal and its pom add commonEnityModule dependency

No alt text provided for this image

Step 3) import all entities from the external commonEnityModule

No alt text provided for this image

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

No alt text provided for this image

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 {}

No alt text provided for this image

Have fun launching your application successfully.

To view or add a comment, sign in

More articles by Bhushan Patil

  • JMeter

    I choose this article because as developers we need to know this tool for api testing. As a developer, when we test our…

  • Spring Security with JWT for REST API

    #javadeveloper #javaprogramming #springsecurity #jwt #java #springboot #springframework #javafullstackdeveloper…

  • Postgres insert or update trigger WHEN condition

    Postgres Professional#javadeveloper #javaprogramming #java #springboot #springframework #javafullstackdeveloper…

  • Efficiently Read Large Excel

    #java #springboot #springframework #javafullstackdeveloper #javabackenddeveloper #javajobs #javadevelopment…

  • How to read data from Excel using Java?

    #java #springboot #springframework #javafullstackdeveloper #javabackenddeveloper #javajobs #javadevelopment…

    5 Comments
  • How to Integrate Apache Kafka in Your Spring Boot Application

    #java #springboot #springframework #javafullstackdeveloper #javabackenddeveloper #javajobs #javadevelopment #rabbitmq…

  • Spring Boot RabbitMQ Producer and Consumer Example

    #java #springboot #springframework #javafullstackdeveloper #javabackenddeveloper #javajobs #javadevelopment #rabbitmq…

  • Spring Boot Scheduler

    Hi Java LinkedIn family, I am sharing a new concept. In this article, you will learn how to schedule tasks in Spring…

  • The best way to externalise Spring Boot application.properties

    The best way to externalise Spring Boot application.properties First Create a Spring Boot application By default your…

  • Retrieving a POJO DTO projection with Spring Data JPA

    Hi Java LinkedIn family, I am sharing a new concept. I have noticed that many Java developers are doing the bad…

Explore content categories