2

i need to pass the schema name dynamically to the entity

 @Entity
 @Table(name = "customer_table" schema="${dynamicSchemaName}")
 @JsonIgnoreProperties

 public class Customer implements Serializable {
      //....
 }

how can i replace ${dynamicSchemaName} with the schema that will be picked by the code where this entity is called?

  • 1
    I think your best bet would be to have different datasources with different schema and call the proper datasource at different places – XtremeBaumer Jun 28 '19 at 09:18
  • 1
    I did something similar. But I just needed to choose the schema name during application initialization. It didn't change after application startup. Do you need something different? https://stackoverflow.com/a/33865136/3405171 – v.ladynev Jun 28 '19 at 09:19

1 Answers1

1

The simple answer is that you can't. Although there are hacks and ways to inject dynamic data into an annotation, that doesn't exist for Hibernate. Annotations are defined at compile time and read at run time.

Yserbius
  • 1,375
  • 12
  • 18