2011-11-02 142 views
1

在SmartGwtEE項目中,我有.ds.xml文件描述的數據源的層次,這裏是其中的一些:DataSource.getInheritsFrom()失敗,並拋出ClassCastException

BaseElement_DS.ds.xml

<DataSource ID="BaseElement_DS" serverConstructor="com.isomorphic.jpa.JPADataSource" 
    beanClassName="lnudb.server.model.BaseElement"> 
    <fields> 
     <field name="id" type="sequence" hidden="true" primaryKey="true" /> 
     <field name="name" type="text" title="Name" required="true" /> 
     <field name="dsId" type="text" title="Datasource" hidden="true"/> 
    </fields> 
</DataSource> 

Human_DS.ds.xml

<DataSource ID="Human_DS" serverConstructor="com.isomorphic.jpa.JPADataSource" 
    beanClassName="org.zasadnyy.lnudb.server.model.Human" inheritsFrom="BaseElement_DS" 
    useParentFieldOrder="true"> 
    <fields> 
     <field name="surname" type="text" /> 
     <field name="birthday" type="date" title="Birthday" required="false" /> 
    </fields> 
</DataSource> 

PROBL EM:當我試圖讓父數據源ID代碼

String parentDsId = DataSource.get("Human_DS").getInheritsFrom(); 

ClassCastExeption從getInheritsFrom內提出()方法:

java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$ cannot be cast to java.lang.String 

我會感謝任何幫助。

回答

0

這樣你就不會得到異常不再:

String parentDsId = DataSource.get("Human_DS").getInheritsFrom() + ""; 

但是,我不知道這是否是你的目的「OK」。如果這對你不合適,嘗試創建一個Javascript對象並將前面提到的值賦予它。我希望這有幫助。

+0

感謝您的快速回答,但這並沒有幫助,這種解決方案可以在JavaScript中幫助,但不能在Java中幫助。 – zasadnyy

相關問題