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

前提是你 提交于 2019-12-10 16:27:56

问题


I have two schema(claim and policy). For both schema am using same Entity class. 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 ? 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();
}

回答1:


You need to have two different mappings for different schema, so you have to create two java mapping classes and annotate them with the Table annotation to mark the schema for each specific entity.



来源:https://stackoverflow.com/questions/32005520/is-it-possible-to-maintain-the-different-schema-in-same-entity-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!