I was trying to use flex web services to connect to a java
back end. i was successfully able to retrieve data from the
database which is by the way connected through hibernate. When i
try to add a record to the database i am encountering a problem.
Because of the xml created by the web service i cannot add a record
with inputting a value for the ID property of my record. This ID
property is an auto incremented value so as you can see this is an
undesired result. Is there anyone that has successfully
incorporated Flex + hibernate and if so can you help with the
present problem. In addition could any also help to explain why i
get a "nan" error when i try to pass a Typed Object to the Web
The first problem you need to deal with is the "NaN" problem.
The problem is caused by the fact that in Flex, a Number has no
concept of null, so when you send the object with an uninitialized
ID, Flex sends "NaN" to represent the uninitialized Number. You
can't use int either because it can't be null, and you need the ID
to be null on the Java side to do the initiail insert.
The solution is to use the "*" data type. For example "var
id:*;". When data comes back from a web service, the id will be
replaced by a Number or int holding a value which won't cause
future problems. When you create a new object to send to a save,
you'll never set an ID, so it will remain null when it is sent to
the web service.
This will be the least of your problems using Hibernate with
Web Services. There are 2 other problems you'll have to deal with
if you ever want to hold a collection of child objects in a
1) If you use lazy loading (which is reccommended), you'll
get Lazy Loading exceptions when you try to serialize the object
because of the proxy set Hibernate uses.
2) If the association is bidirectional (also reccommended),
you'll have circular reference problems.
Both of these issues have solutions, but it can get messy. My
solution was to detect ininitialized "PersistentSet" objects and
replace with null, and to set children's parent references to null
before serializing the object. I then have to put it all back
together whem an object comes in. Just omething to keep in mind
when doing the data modelling.