I have a situation where i have relations like this:
A person has one or more addresses. A customer has one or more addresses.
Person,customers and addresses are separate tables.
I used to do this with the @OneToMany relations. This is giving me problems since our flex client is sending me objects wich are created in the client and have to be created in the DB.
If the client sends me a person and customer which reference to the same address hibernate will create two address objects since the two address object are not the same java objects (not the same pointers).
This is a problem which is caused by BlazeDS and Dozer which will create new objects when they are send to the server.
So what i would like to have is the address id in the person and customer object without an relation so hibernate does not create the objects. But when i read a person object i would like to fill a transient address object based on the stored address id.
Does anyone know if this is possible?
There's two issues here:
There are frameworks available to help, but the problem doesn't yet have a great universal solution.
dpHibernate will help with the lazy loading of the data - ie:
when I read a person object I would like to fill a transient address object based on the stored address id
Unfortunately entity resolution is not yet supported across multiple calls in dpHibernate. ie - If a call returns the same object in two locations within a server call (eg., the same Address
entity in both Customer id:1
and Customer id:2
then you'll receive a single instance of Address
in both customer objects.
However, if the data is loaded over seperate calls, you'll receive two instances of Address
. This is an issue which is slated for implementation in v3.
I believe the Cairngorm Integration library attempts to address this issue, however the wiki suggests it's LCDS only. You could investigate what is required to implement this with BlazeDS. I haven't used this library, so can't speak to how well it will solve your issues.