OK, so I think you may have the metadata registered twice perhaps, once dynamically and once statically. I say this because the class you have an instance of is DynamicDataObjectImpl and not AnyTypeDataObjectImpl. I wonder whether a dynamic registration of the schema is masking the registration of the static classes?
Kelvin. 2009/6/15 Viatcheslav Kuravskiy <[email protected]>: > I post my code once again: > > HelperContext hc = HelperProvider.getDefaultContext(); > PersonFactory.INSTANCE.register(hc); > > DAS das = DAS.FACTORY.createDAS(getConfig(configFile)); > > Command readPerson = das.getCommand("getFirstPerson"); > DataObject root = readPerson.executeQuery(); > > Person p = PersonFactory.INSTANCE.createPerson(); > > p = (Person)root.getDataObject("Person[1]"); > > The exception is: > > java.lang.ClassCastException: > org.apache.tuscany.sdo.impl.DynamicDataObjectImpl cannot be cast to > sdo.Person > > -- > Best regards, > V.Kuravskiy > > kelvin goodson wrote: >> >> Could you please supply some detail of the exception. >> >> I note that in some of the postings above the schema seems to have a >> type of "erson" - Similarly there are element names of "ame", "ge" and >> "d" - is this what you have or just a cut and paste error? >> >> Kelvin. >> >> 2009/6/12 Viatcheslav Kuravskiy <[email protected]>: >>> >>> kelvin goodson wrote: >>>> >>>> I'm guessing your exception is a ClassCastException because the actual >>>> class is AnyTypeDataObjectImpl, and not PersonImpl. For the DAS to >>>> create instances of your generated class it would a) have to be using >>>> the default helper context, and b), understand that Person objects are >>>> from the http://www.example.org/person namespace. Perhaps someone who >>>> is familiar with DAS could take a look at this? >>>> >>>> Kelvin. >>>> >>>> 2009/6/10 Viatcheslav Kuravskiy <[email protected]>: >>>> >>>>> Hello to all! >>>>> >>>>> How can I map a DataObject to a Java object? My situation is: >>>>> >>>>> 1) From person.xsd was generated Person.java, PersonFactory.java, >>>>> PersonImpl.java and PersonFactory.java. XSD2JavaGenerator was used for >>>>> it. >>>>> >>>>> Here is person.xsd: >>>>> >>>>> <?xml version=.0" encoding="UTF-8"?> >>>>> <schema xmlns=ttp://www.w3.org/2001/XMLSchema" >>>>> targetNamespace=ttp://www.example.org/person" >>>>> xmlns:tns=ttp://www.example.org/person" elementFormDefault="qualified"> >>>>> >>>>> <complexType name=erson"> >>>>> <sequence> >>>>> <element name=ame" type="string"></element> >>>>> <element name=ge" type="int"></element> >>>>> <element name=d" type="int"></element> >>>>> </sequence> >>>>> </complexType> >>>>> </schema> >>>>> >>>>> 2) I have a RDB with a table PERSON and columns ID:integer, >>>>> NAME:varchar, >>>>> AGE:integer. >>>>> >>>>> Here is a part from Config.xml: >>>>> >>>>> <Table tableName=ERSON" typeName="Person"> >>>>> <Column columnName=D" primaryKey="true"/> >>>>> </Table> >>>>> >>>>> <Command name=etFirstPerson" SQL="select * from PERSON where ID=1" >>>>> kind=elect"/> >>>>> >>>>> >>>>> 3) I do: >>>>> >>>>> HelperContext hc = HelperProvider.getDefaultContext(); >>>>> PersonFactory.INSTANCE.register(hc); >>>>> >>>>> DAS das =AS.FACTORY.createDAS(getConfig(configFile)); >>>>> >>>>> Command getPerson =as.getCommand("getFirstPerson"); >>>>> DataObject root =etPerson.executeQuery(); >>>>> >>>>> DataObject p1 =root.getDataObject("Person[1]"); >>>>> >>>>> Person p2 =ersonFactory.INSTANCE.createPerson(); >>>>> >>>>> p2 =Person) p1; // Here I have exception >>>>> >>>>> >>>>> Can somebody help me to solve this problem? >>>>> >>>>> >>>>> Best regards, >>>>> V.Kuravskiy >>>>> >>>>> >>>> >>> Actually I did the same thing from this example: >>> http://tuscany.apache.org/workingwithstaticdataobjects.html >>> >>> Just >>> >>> SDOUtil.registerStaticTypes(CustomerFactory.class); >>> >>> was changed with >>> >>> HelperContext hc = HelperProvider.getDefaultContext(); >>> PersonFactory.INSTANCE.register(hc); >>> >>> But unfortunately it's not working. >>> >>> V.Kuravskiy >>> >>> >> >
