I am trying to create a structure to allow customization in my spring boot project. When there are two Entities with the same name, I want the Entities in the specified package to crush the entity in the other package. How can I do this? I couldn't do it with ClassLoader because spring boot scans Entities with @EntityScan.
Main class
@SpringBootApplication
@EnableJpaRepositories(basePackages = "com.project")
@EntityScan(basePackages = {"com.project"})
public class ProjectMain {
SpringApplication.run(ProjectMain.class, args);
}
Entity in com.project.data.entity
package
package com.project.data.entity;
import jakarta.persistence.Entity;
@Entity
public class User {
...
}
Entity in com.project.data.domain
package
package com.project.data.domain;
import jakarta.persistence.Entity;
@Entity
public class User {
...
}
I cannot solve the problem with ClassLoader because Spring Boot manages Entities differently. I get the following error when there is an Entity with the same name. As I said, my goal is to ignore more than one entity with the same name.
Error creating bean with name 'openEntityManagerInViewInterceptor' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration$JpaWebConfiguration.class]: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Entity classes [com.project.data.entity.User] and [com.project.data.domain.User] share the entity name 'User' (entity names must be distinct)