简体   繁体   中英

Is there a way to toggle an annotation based on the active profile in Spring

In our project, we have database definition like:

@Entity
@Table(name = "\"com.sap.s4hc.fnd.circ::PRECHECK_ITEM\"")
@Cacheable(false)
public class PrecheckItem extends AdminField implements Comparable<PrecheckItem>, Serializable 

However, as the database naming schema follows SAP HANA's convention ( namespace::table_name ), it doesn't play nicely with Spring Boot/Hibernate. The database in production environment is created with means other than JPA/Hibernate.

The current implementation works fine on cloud, but in local development environment, where H2 database is used, I believe Hibernate doesn't support the current naming strategy. Hence a Table "com.sap.s4hc.fnd.circ::PRECHECK_ITEM" not found; is always thrown.

Apparently, I can have two different set of entity classes ready to mitigate this issue as PrecheckItemLocal and PrecheckItemCloud , where I use profiles to activate them respectively, but it would be really nice if I can simply:

@Entity
@Profile ("cloud") {@Table(name = "\"com.sap.s4hc.fnd.circ::PRECHECK_ITEM\"")}
@Cacheable(false)
public class PrecheckItem extends AdminField implements Comparable<PrecheckItem>, Serializable

Is there an implementation like this available?

unfortunetly so far there is no way to do that in the way you would like to. So, the only way is the one you mentioned to have two different sets of entities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM