I have Hibernate, Spring, BlazeDS and a Flex client.
My domainObject1 on the server has a primary key that is an Integer. It also contains a HashSet of other domain objects (domainObject2, domainObject3 etc).
On the Flex client the primary key is an int for all of the objects.
When I send a new object from the Flex client to the server to be saved, domainObject1 is converted from a Flex object to a Java object, and is given a primary key value of 0. The same happens for each of the domainObjects in the Flex ArrayCollection. domainObject1 is saved correctly by Hibernate, but the other domainObjects throw an UnexpectedRollbackException. They do this because Hibernate seem to think that these domainObjects already exist in the database. I know this, because if I set there primary key to null before saving, everything works fine (I also see Hibernate trying to update the object, rather than saving it).
In the past I have used the DTO layer to get around this and simply checked if the primary key being given to each domainObject was greater than 0 before setting it. I am not using a DTO layer anymore. I am therefore wondering how to get around this problem. Is it a bug in the Spring/Flex framework, or am I doing something wrong?
Thanks for any tips.


Reply With Quote