I'm using Hibernate on an application server to work with AMF serialized data types. What this means is that the client (AS3/Flash Player) declares classes and the way that they are serialized (eg. writeObject() writeUTF() etc.) and the server that runs Hibernate takes these objects and deserializes them, mapping them to Java classes specified by the client. The client specifies this alias via an AS3 method call "registerClassAlias("path.of.my.JavaClass", ClientClass);". When the server receives an object, it finds the corresponding alias for it as specified by the client, and deserializes its fields to an instance of that Java class. The server I am using already handles all of this for me, so it's no big deal to use.
The workflow is this. Client connects to server. Client issues a RMI call to the server, which uses Hibernate to fetch whatever objects the client desires. Server returns those values to the client, serializing them into AMF so the client can read them as native values. The client performs some changes on them and sends them back to the server via a RMI call telling the server to update them. They are deserialized and recognized as regular Java objects, and then they are passed to Hibernate for updating/persisting/deleting, etc.
However, I have experienced some problems when using Hibernate with these objects. They are annotated POJO's, so Hibernate shouldn't see them as anything different than the Java objects that they are, right? I mean, I can work with them like native Java objects, because they are native Java objects with values injected on deserialization of the AMF types.
Anyway, I often receive the following errors. I often get a TransientStateException when calling "session.update(value)", which tells me the object I passed is transient/detached and I should try calling an operation on it before I flush the session. The same thing sometimes occurs after calling "persist." I have also experienced quite a few problems with using collections, though I am absolutely certain that the collections are serialized correctly; however, there are alternative ways of updating/persisting/deleting objects in a collection than the current way I'm doing it (which is done all by cascading). The main workaround I have found to these errors is creating a proxy object for each object I wish to perform persistence operations on, essentially loading the instance with a given "id" from the database, then applying the changes in the newer object to the older one from the db, then session.update()'ing it. This is obviously a messy workaround.
I guess what I'm asking is, how can I get around this? Is there a way I can explicitly attach an instance to a session and perform all of these operations without fault? Can anyone help me out with this?
|