I have a Class with @Table annotation, currently I directly set the Name value like this :
@Data
@Entity
@NoArgsConstructor
@Table(name = "US_STUDENTS" )
public class Student {
// some properties
}
I have a table in DB named MasterCountries which have a Column name - value = countryPrefix - "US_"
When the Spring boot app run, I want to take this data from the DB and use it as part of the @Table name value to make it like this :
@Data
@Entity
@NoArgsConstructor
@Table(name = countryPrefix + "STUDENTS" ) // so the end result will be "US_STUDENTS"
public class Student {
// some properties
}
I've google'd and still have not found a solution to this, the reason is because I want to make it dynamic, whenever this spring boot service need to be redeployed for other country, just need to retrieve the specific countryPrefix from the DB, so no need to change the code again for each country Deployment.
for the repository I set up an interface that extends JpaRepository as shown below :
public interface MasterCountriesRepository extends JpaRepository<CountriesSetting, Long> {
CountriesSetting findByCountryCode(String countryCode);
}
and for the CountriesSetting entity :
@Data
@Entity
@NoArgsConstructor
@Table(name = "MasterCountries" )
public class CountriesSetting {
// some properties
}
Is this possible to achieve in spring JPA ? please ignore any mistype or minor syntax problem, as this is not the real code. Thanks in advance.