映射具有相似列结构的多个表
Mapping multiple Tables with similar column structure
我有一个要用于两个表的 EJB。除了其中一个表中的一些附加列外,这两个表具有相同的列。如何使用javax.persistence.Table提供的@Table注解来完成。我不希望使用 @secondaryTable 重新映射列,因为它们具有相同的名称。让我知道是否有任何方法可以实现这一目标。
如果我理解的很好,你需要@MappedSuperclass注解。
我正在复制 here 中的示例。
创建超级 class,它将包含两个表都具有的公共列:
@MappedSuperclass
public class GenericCommonTable {
private String address;
public Address getAddress() { ... }
public void setAddress(Address addr) { ... }
}
添加共享相同列的 2 个具体表:
@Entity
public class ConcreteTableOne extends GenericCommonTable {
//your xtra columns here
}
@Entity
public class ConcreteTableTwo extends GenericCommonTable {
//your xtra-columns here
}
希望对您有所帮助
我有一个要用于两个表的 EJB。除了其中一个表中的一些附加列外,这两个表具有相同的列。如何使用javax.persistence.Table提供的@Table注解来完成。我不希望使用 @secondaryTable 重新映射列,因为它们具有相同的名称。让我知道是否有任何方法可以实现这一目标。
如果我理解的很好,你需要@MappedSuperclass注解。
我正在复制 here 中的示例。
创建超级 class,它将包含两个表都具有的公共列:
@MappedSuperclass public class GenericCommonTable { private String address; public Address getAddress() { ... } public void setAddress(Address addr) { ... } }
添加共享相同列的 2 个具体表:
@Entity public class ConcreteTableOne extends GenericCommonTable { //your xtra columns here } @Entity public class ConcreteTableTwo extends GenericCommonTable { //your xtra-columns here }
希望对您有所帮助