【发布时间】:2013-03-06 17:33:53
【问题描述】:
我正在尝试使用 Oracle 和 JPA 构建数据库模式。我是 JPA 的新手,我总是直接使用 sql。 我需要创建两个表:第一个包含当前的 VOIP 呼叫,另一个包含这些呼叫的历史记录。这两个表是相同的。 在 JPA 中我写了这个:
@Entity
@Table(name = "voip_currentCalls")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class VoipCurrentCall implements Serializable {
private static final long serialVersionUID = 1L;
protected CompositeID id;
protected Timestamp startTime;
protected Timestamp endTime;
protected String calledNumber;
protected String callingNumber;
protected Person contact;
protected CallSource source;
protected CallStatus status;
protected CallType type;
protected CallStage stage;
@Entity
@Table(name = "voip_historyCalls")
public class VoipHistoryCall extends VoipCurrentCall implements Serializable {
...
如您所见,第二个表没有其他字段,但它只是第一个表的扩展。 当我尝试将 VoipCurrentCall 转换为 VoipHistoryCall 时,我得到 java.lang.ClassCastException: VoipCurrentCall cannot be cast to VoipHistoryCall。
你有什么建议吗?我可能错过了一些东西。 提前感谢大家!
【问题讨论】:
-
您不能将超类转换为子类。