0

AppEngine 仅支持 JPA 继承的“TABLE_PER_CLASS”和“MAPPED_SUPERCLASS”。不幸的是,不支持“JOINED”,尤其是“SINGLE_TABLE”。

我想知道实现 SINGLE_TABLE 替代方案的最佳替代方案是什么?

我唯一的要求是: 1) 有单独的类,如 AbstractEmployee、InternalEmployee、Exmployee。2) 能够对所有员工运行查询,从而产生 InternalEmployee 和 ExternalEmployee 实例。

我唯一想到的是使用包含所有字段的“大”员工对象?还有其他想法吗?

PS:通过http://code.google.com/p/googleappengine/issues/detail?id=8366投票支持适当的“SINGLE_TABLE”

4

2 回答 2

1

理论上,您可以使用 @Embeded 和 @Embeddable 将相关字段分组到一个对象中。所以你会有一个看起来像这样的类。

@Entity
public class Employee {
     // all the common employee fields go here 
     //

     // the discriminator column on Employee class lets you be specific in your queries          
     private Integer type; 

     @Emebded 
     private Internal internal; // has the fields that are internal

     @Embeded
     private External external; // has the fields that are external 

     equals & hashcode that compare based on the discriminator type and other fields 
} 
于 2012-10-31T13:54:14.407 回答
0

AppEngine 支持和不支持的内容在那里具有误导性。AppEngine 使用属性存储,因此任何 Kind 都可以具有任何属性。因此,原则上,一个 Kind 可以包含 InternalEmployee 和 ExternalEmployee “实例”。AppEngine JPA 实际做的唯一一件事就是将类的所有字段存储在单个 Kind 对象中。这并不排除将子类型存储在同一种类中(具有特定于子类型的字段的额外属性),这相当于“单表”。

PS,在“AppEngine”整体上提出一些问题不会得到任何回应(看看那里的其余问题;-)),记住这里受影响的代码在它自己的项目中http://code .google.com/p/datanucleus-appengine 并拥有自己的问题跟踪器

于 2012-10-31T14:11:39.117 回答