0

I am trying to set the name of my tables in the entities using parameters from the application.yml

This is the entity:

@Entity
@Table(name = "${database.tableName}")
public class enitityName {...}

And this would be the application.yml:

database:
    tableName: entityName

This doesn't work to me. Is there any way to achieve this? Can someone give me some ideas?

I need to do it because i have the tables for my differents enviroments in the same database, so the name of the tables are like these: table_test, table. And they would be the same class in my code

Thanks

Paplusc
  • 1,080
  • 1
  • 12
  • 24
  • Why do you want to do that? The reason I am asking is to propose potential workarounds, because I believe doing exactly what you ask is not possible. – Nikos Paraskevopoulos Aug 26 '19 at 14:30
  • I need to do it because i have the tables for my differents enviroments in the same database, so the name of the tables are like these: `table_test`, `table`. And they would be the same `class` in my code – Paplusc Aug 26 '19 at 14:45
  • 1
    If Hibernate is your underyling JPA provider, it can use naming strategies for tables. From a quick search, these are relevant: [link1](https://stackoverflow.com/questions/4313095/jpa-hibernate-and-custom-table-prefixes), [link2](https://www.baeldung.com/hibernate-field-naming-spring-boot). – Nikos Paraskevopoulos Aug 26 '19 at 14:53
  • Sweet, i will try to find a solution using the naming strategies, thanks – Paplusc Aug 26 '19 at 15:08

1 Answers1

0

What you are trying to do is not possible.However, I found a similar problem your question, you can check from this question.

Hatice
  • 874
  • 1
  • 8
  • 17