In @Table(name = “tableName”) - make “tableName” a variable in JPA

后端 未结 5 1394
無奈伤痛
無奈伤痛 2020-12-16 14:35

I am using JPA and I need to make the \"tableName\" a variable.

In a database, I have many tables, and my code needs to access the table where I specify it to read.

5条回答
  •  抹茶落季
    2020-12-16 15:26

    If you want only to reference/read the table name, it is possible as in the code below. If you want to change, it is not possible as Pascal said.

    @Entity
    @Table(name = Database.tableName)
    public class Database implements Serializable {
        public static final String tableName = "TABLE_1";//this variable you can reference in other portions of your code. Of course you cannot change it.
        ...............
    }
    

提交回复
热议问题