Sandiip Patil
Sandiip Patil

Reputation: 446

Change schema name for different environment in JPA annotation in Telosys generated code

I am generating my classes using spring jpa template in Telosys generator tool. It works as expected, however, my project has different database schemas for different environment which I can't handle. So my entity classes need to have respective schema name which will mean me connecting each database schema and generating environment specific classes.
I am trying to pass the schema name from gradle variable and use that in entity class

schema = "${property.schema.name}"

But since these are generated classes by Telosys, all JPA annotations are handled by the template. Is there a way to set the schema name in the annotation like above? or any alternate solution to the problem of different schemas is appreciated

Upvotes: 0

Views: 638

Answers (1)

lgu
lgu

Reputation: 2460

If your database schema is the same for all entities you can just define a specific project global variable in the file "telosys-tools.cfg".
See : https://doc.telosys.org/configuration-and-variables
In your case: ProjectVariable.DBSCHEMA = yourschema
You can use it directly in the templates with ${DBSCHEMA}:

If you have specific schema only for certain entities you can use the @DbSchema(your-schema-name) annotation (at entity level) in the ".entity" files
See : https://doc.telosys.org/dsl-model/annotations#dbschema-string
Annotations like @DbSchema and @DbCatalog are automatically used by $jpa object in the templates.

Upvotes: 0

Related Questions