Hibernate with dynamic table names

Asked

Viewed 129 times

0

Good Morning/Afternoon/Evening Staff! in a scenario where a comic table must have a concatenated name and dates as this would look with Hibernate given that the base name is annotated in the model.

How is it:

@Entity
@Table(name="nome_da_tabela")

As I am imagining:

@Entity
@Table(name="nome_da_tabela"+data)

I would like to know if it is possible to do this or even something like that, I thank you in advance.

  • This date would be single or current ?

  • Dude, it’s a table that would have that date in the nomenclature for "Versionar" the table, because it is a system of fiscal nature it is necessary to maintain the information of taxation that over time are changed the date would be precisely to specify when is the taxation.Although more specifically would be used only the month and the year.

1 answer

0


If Voce is using Hibernate you can extend the Improvednamingstrategy class (which inherits from the Namingstrategy interface and generates the methods) and overwrite the method that generates the table in the database. The methods and signatures can check on the link:

https://docs.jboss.org/hibernate/orm/3.5/api/org/hibernate/cfg/ImprovedNamingStrategy.html

Overwrite methods as per use:

@Override
public String columnName(String columnName)
{
    return columnName;
}

@Override
public String tableName(String tableName)
{
    return tableName;
}
  • Who will inherit these methods of Improvednamingstrategy is the model I want with the modified name is not?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.