0

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

Sandiip Patil
  • 456
  • 1
  • 4
  • 21

1 Answers1

0

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.

lgu
  • 2,342
  • 21
  • 29
  • Thank you @Igu. I really appreciate it. My schema name is changing for all entities as environment changes. And because I do not want to re generate all the entity classes and commit the code for just schema name change I am trying to find a way that Iit could be configured explicitly while I either deploy it or build it using gradle or properties. What would be your suggestion? – Sandiip Patil Jul 06 '22 at 16:30
  • Not sure I fully understand your need. But if you don't want to re-generate, then the solution cannot be provided by the generator. You can try to dive inside JPA/Hibernate. Perhaps with hibernate.default_schema in configuration ? – lgu Jul 06 '22 at 17:56
  • Yes @Igu, I am looking into default schema config. One solution I could find was to have schema placeholder in entity class annotation and pass the variabl from gradle. But since it is generated by Telosys, can you please suggest what should I do to put like in my question instead of actual schema name – Sandiip Patil Jul 06 '22 at 18:44
  • The docs url is not working @Igu. – Sandiip Patil Jul 06 '22 at 18:46
  • it was just a temporary problem with the host, it works normally now. – lgu Jul 07 '22 at 10:23
  • DbSchema annotation needs an import @Igu. Can you help with an example. what change should I do in my template .entity – Sandiip Patil Jul 14 '22 at 17:40