Answer the question
In order to leave comments, you need to log in
How to change database schema in Entity Hibernate?
Hi, friend. I want to understand how to dynamically change the schema in entities.
In dev environment DEV.EntityValue in prod PROD.EntityValue.
Wouldn't want to specify @Table(name = "VALUES", schema = "DEV").
@Entity
@Table(name = "VALUES")
public class EntityValue extends BaseEntity {}
Answer the question
In order to leave comments, you need to log in
Stop, friend! You are clearly not going there!
The code should not depend on the environment at all. It's too much of a connection.
Prod, test, qa, staging, dev (etc..) should be separated at the configuration level.
Hello!
If I understood correctly, then you have a base in which there are 2 schemes. And depending on the profile you want to switch schemes?
I see a couple of options here:
1) at the gradle level || maven define schemas.
https://stackoverflow.com/questions/47240702/jpa-e...
https://stackoverflow.com/questions/1149352/using-...
<profiles>
<profile>
<id>production</id>
<properties>
<schema.name>production_schema_name</schema.name>
</properties>
</profile>
<profile>
<id>test</id>
<properties>
<schema.name>test_schema_name</schema.name>
</properties>
</profile>
</profiles>
@Table(name = "VALUES", schema = "DEV").
@Table(name = "VALUES", schema = "PROD").
@Profile
As an option, you can create an Interceptor - the successor of org.hibernate.EmptyInterceptor and in the onPrepareStatement method replace at least the scheme, at least the table name. To do this, you need to have information about the build profile (dev / prod).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question