Using @Table Hibernate

0

How do I use the @Table annotation of hibernate using a variable that returns the name of the table, for example @Table(name = "dep4"+Dados.getCodEmp) ? I am using this form but I get the following error:

The value for annotation attribute Table.name must be a constant expression

I need this because in the system database in question the tables are generated with the following nomenclature prefix + the code assigned to the company, for example dep4+(CodEmp) . This code I get from a text file that is inside the application directory.

    
asked by anonymous 31.01.2018 / 12:11

2 answers

1

I do not think I can do this unfortunately.

@Table is a Java annotation, and Java annotations can not receive values in Runtime time. Java annotations can only receive constants, as the error message tells you.

    
31.01.2018 / 12:38
-1

You should create a Generating Database Schemas strong>  or Interceptors to schema your database .

public class Main {

   public static void main(String[] args) {
     Persistence.generateSchema("samplePU", null);
   }
}

Take a look at the links.

    
31.01.2018 / 12:55