简体   繁体   English

是否可以在同一个实体类中维护不同的模式

[英]is it possible to maintain the different schema in same entity class

I have two schema(claim and policy). 我有两个架构(声明和政策)。 For both schema am using same Entity class. 对于两个架构,我使用相同的Entity类。 My problem is, claim schema has column city but policy schema does have city column. 我的问题是,声明架构有列城市但政策架构确实有城市列。 So If I use entity class by policy schema I get error. 所以如果我按策略模式使用实体类,我会收到错误。 is this only the way to change the Entity class for each schema ? 这只是改变每个模式的Entity类的方法吗? or is it possible to maintain the different schema in same entity class? 或者是否可以在同一个实体类中维护不同的模式?

My Entity class : 我的实体类:

@Entity
@Table(name = "Table_name")
public class X {

   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)
   @Column(name = "xxx")
   private int xxx;

   @Column(name = "yyy")
   private String yyy;

   @Column(name = "city")
   private String city;      // only claim schema 
 }  

I get the schema like this, 我得到这样的架构,

if(id.startsWith("SW")){
                session = getSWSession();
}
if(id.startsWith("HW")){
                session = getHWSession();
}

您需要为不同的模式使用两个不同的映射,因此您必须创建两个Java映射类,并使用Table批注对它们进行批注,以标记每个特定实体的模式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Jpa 在不同的表(相同的模式)中保存相同的实体 - Saving same entity in different tables(same schema) using Jpa JPA 2 个不同的本地查询,具有相同的 class 作为实体 - JPA 2 different native queries with same class as entity 是否可以为同一类设置不同的mouseClicked()? - Is it possible to make different mouseClicked() for the same class? Spring 3 + Hibernate 4将数据库中的不同表加载到同一实体类中 - Spring 3 + Hibernate 4 Load different Tables from database into same entity class JPA,如何使用相同的类(实体)来映射不同的表? - JPA, How to use the same class (entity) to map different tables? JBoss-同一应用程序中的不同类加载系统-可能吗? - JBoss - different class loading system in the same application - possible? 是否可以在具有不同ID的Eclipse插件中使用相同的包和类名? - Is it possible to use the same package and class name in Eclipse plugins with different ID? 是否可以使用Hashmap在Java中存储同一类的不同实例? - Is it possible to store different instances of the same class in Java with Hashmap? 是否可以对扩展相同基类的不同对象的列表进行包裹/取消包裹? - Is it possible to parcel/deparcel a list of different objects that extend same base class? 具有嵌套在不同实体类中的ID的实体类 - Entity Class with an Id nested in a different Entity Class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM