我正在嘗試使用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