是否可以在同一实体类中维护不同的架构 [英] is it possible to maintain the different schema in same entity class
问题描述
我有两个模式(声明和策略).对于两个架构,都使用相同的Entity类. 我的问题是,声明架构具有列city,但是策略架构却具有city列.因此,如果我通过策略架构使用实体类,则会出错. 这是更改每个架构的Entity类的唯一方法吗?还是可以在同一实体类中维护不同的架构?
我的实体类:
@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
}
我得到了这样的模式,
if(id.startsWith("SW")){
session = getSWSession();
}
if(id.startsWith("HW")){
session = getHWSession();
}
您需要为不同的架构提供两个不同的映射,因此您必须创建两个Java映射类,并使用Table注释对其进行注释,以标记 ="http://docs.oracle.com/javaee/6/api/javax/persistence/Table.html#schema%28%29" rel ="nofollow">模式. >
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();
}
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.
这篇关于是否可以在同一实体类中维护不同的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!