我正在尝试使用Oracle和JPA构建数据库模式。我是JPA新手,我一直直接使用sql。 我需要做的是创建两个表格:第一个包含当前VOIP呼叫,另一个包含这些呼叫的历史记录。这两张表是相同的。 在JPA我写了这个:JPA Cast Exception
@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不能转换为VoipHistoryCall。
你有什么建议吗?我可能错过了一些东西。 提前感谢大家!
您不能将超类转换为子类。 – 2013-03-18 11:43:29