Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

ClassCastException

Avatar

Former Community Member
Hi,<br /><br />I'm trying to get LCDS working with Flex for some days now.<br />I retrieve information from a Mysql database, using a jdbc driver, and display the result on the client side into a Flex datagrid.<br />The retrieving is working fine, but when I edit a cell and the application tries to update the information I get this message into the server console:<br /><br />"[Flex] Exception executing assembler operation. incomingMessage: Flex Message (flex.data.messages.DataMessage)<br /> operation = update<br /> id = ASObject(19958876){id=4}<br /> clientId = 612044C2-5AF9-A14D-6E16-232B84D96DCB<br /> correlationId = 6569793A-68D2-865B-2B76-232BE4CB2585<br /> destination = simplefdms<br /> messageId = AE74B75E-36EB-57A0-72EE-232BE4CBB99E<br /> timestamp = 1190296020296<br /> timeToLive = 0<br /> body =<br /> [<br /> [<br /> name<br /> ],<br /> {name=gustave, id=4},<br /> {name=gustavek, id=4}<br /> ]<br /> hdr(DSEndpoint) = my-rtmp<br /> hdr(DSId) = 9ADD4310-600F-0849-CEBF-32A79BFFBD08<br /> exception: <b>java.lang.ClassCastException</b><br /> at EmployeeManagement.EmployeeAssembler.updateItem(EmployeeAssembler.java:54)<br /> at flex.data.adapters.JavaAdapter.doUpdateItem(JavaAdapter.java:1659)<br /><br />..."<br /><br />The exception is raised when I try to cast the "Object" sent by the client to the type of the data:<br /><br />Employee ct = new Employee();<br />ct = (Employee)newObj; // HERE<br /><br />It seems that the class loses its type when sent back by the client... even if the as version of the class is correctly linked with its java counterpart...<br /><br />Someone could help me please?<br /><br />--<br /><br />Here are some of the files used. I don't know if I've made something wrong...<br /><br /><b>C:\lcds\jrun4\servers\default\simple\WEB-INF\src\EmployeeManagement\Employee.java<br />&<br />C:\lcds\jrun4\servers\default\simple\WEB-INF\classes\EmployeeManagement\Employee.class</b><br /><br />package EmployeeManagement;<br /><br />public class Employee {<br /> private int id;<br /> private String name;<br /> <br /> public Employee () {<br /> }<br /> <br /> <br /> /**<br /> * @return the id<br /> */<br /> public int getId() {<br /> return id;<br /> }<br /> /**<br /> * @param id the id to set<br /> */<br /> public void setId(int id) {<br /> this.id = id;<br /> }<br /> /**<br /> * @return the name<br /> */<br /> public String getName() {<br /> return name;<br /> }<br /> /**<br /> * @param name the name to set<br /> */<br /> public void setName(String name) {<br /> this.name = name;<br /> }<br /><br />}<br /><br /><b>jrun4\servers\default\simple\EmployeeManager\EmployeeManagement\Employee.as</b><br /><br />package EmployeeManagement<br /> {<br /> [Managed]<br /> [RemoteClass(alias="EmployeeManagement.Employee")]<br /> public class Employee<br /> {<br /> public function Employee() {}<br /> <br /> public var id:int;<br /> public var name:String="";<br /><br /> }<br /> }<br /><br /><b>data-management-config.xml</b><br /><?xml version="1.0" encoding="UTF-8"?><br /><service id="data-service" <br /> class="flex.data.DataService"><br /><br /> <adapters><br /> <adapter-definition id="actionscript" class="flex.data.adapters.ASObjectAdapter" default="true"/><br /> <adapter-definition id="java-dao" class="flex.data.adapters.JavaAdapter"/><br /> </adapters><br /><br /> <default-channels><br /> <channel ref="my-rtmp"/><br /> </default-channels><br /> <br /> <br /> <destination id="fdms-contactmanager"><br /> <adapter ref="java-dao" /><br /> <properties><br /> <source>EmployeeManagement.EmployeeAssembler</source><br /> <scope>application</scope><br /> <metadata><br /> <identity property="id"/><br /> </metadata><br /> </properties><br /> </destination><br /><br /></service>
1 Reply

Avatar

Level 3
Hi Roland,



First, it seems like you don't need to be new'ing an Employee and then assigning to the same variable? Should this:



Employee ct = new Employee();

ct = (Employee)newObj; // HERE



be this:



Employee ct = (Employee)newObj;



As for the ClassCastException, your AS class does define the class mapping using the [RemoteClass(alias="EmployeeManagement.Employee")] metadata so instances from the client should be deserialized as type EmployeeManagement.Employee on the server. I'd recommend adding a debug trace in your assembler updateItem() method and write out newObj's type (i.e. newObject.getClass().getName()). That might provide a clue into what's going wrong.



It looks like the instance is coming through as an untyped Object from the client (an ASObject on the server) which would indicate that no remote class had been defined so the player doesn't send the remote class alias as part of the serialized object stream. Perhaps the client was compiled before the addition of the [RemoteClass] metadata or a cached, old swf is being loaded?



HTH,

Seth