I use two mirror database schemas in my Spring Boot application with Flyway migration on startup: an in-memory H2 - for demo profile, and Postgres - for prod. In each schema, there is a reset_token field which is defined like this:
CREATE TABLE users(
...
reset_token CHAR(36)
);
The problem is that Hibernate expects two different annotations to be used for correct mapping of String property in my User entity into corresponding table column: @Column(columnDefinition = "char") - for H2 and @Column(columnDefinition = "bpchar") - for Postgres. How can I do that? I mean, is it possible to set the value of columnDefinition attribute, based on the active profile, so that not to create two different User entities for each profile?
@Data
@NoArgsConstructor(access = AccessLevel.PRIVATE, force = true)
@RequiredArgsConstructor
@Entity
@Table(name = "users")
public class User {
...
@Column(columnDefinition = "char")
// @Column(columnDefinition = "bpchar")
private final String resetToken;
}