Hi Rohit,
The simplest solution is probably to use a factory method for creating
the unmarshalled objects, with the IUnmarshallingContext as an argument.
The factory method can then access all the information about the current
tag, and use attributes of the tag to retrieve the correct object.
I'm a little leery of documenting this approach of reading attributes in
factory and pre-set methods (even though I use it myself), but as long
as there's a start tag associated with the object being created this
should work properly.
The other alternative is to go to a full-scale unmarshaller. If you
can't get what you need to load the object from the information in the
start tag attributes that's the only other solution.
Sorry for the much-delayed response on this - got lost in the pile.
- Dennis
Rohit Seth wrote:
Hi Alexander,
Thanks for reply. I am using the approach (in a bit different way) you
suggested with the help of post-set method hooks.
First of all, I am not relying on PK as they might be different on target
system. In my postset methods, I am using business keys to fetch the
existing objects. Now after retrieving the object from DB, I get its id
and version and set it on new object.
Reason for doing so are:
1. I am using same approach for updating existing objects. Hence if I
simple change the reference then changes being imported will be lost.
2. Relationships in my case are bit complex like A->B->C->D. Now there
could be a case where this relationship is changed on source system as
A->B->C'->D (where A, B and D are already existing objects). So while
importing I can't simply replace the instance of B being imported with
existing one as I'll lose reference to C'.
3. Moreover even if I replace A's reference to existing instance of B, it
will not be replaced in ummarshalling stack (i think) so later if I'll
access stack I wont get reference to existing object.
thanks
rohit
Hi Rohit,
if I undestood it right, I think you have to add some extra logic to your
importer:
1. After unmarshalling the object which contains the reference (let's call
it object A) access the referenced object (let's call it B) and fetch it's
primary key.
2. Because an object with the same attributes as B (let's call it C) is
already persistent in your system, you can use this PK to fetch it with
Hibernate.
3. Now replace A's reference to B by a reference to the persistent C. B
can be discarded.
4. Make A persistent. Hibernate will recognize that it's connected to C
and that C hasn't changed - so only A will be inserted and it will have a
reference to C.
Alexander
-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Auftrag von
Rohit Seth
Gesendet: Mittwoch, 12. Oktober 2005 17:56
An: [email protected]
Betreff: [jibx-users] Using JibX with hibernate
Hi,
I am trying to use jibx with Hibernate. My goal is to pull
data out of one
system (in form of hibernate objects), marshall them to xml
files using
jibx and then use these xml files to import data on some other system.
I am able to export data from source system successfully but
having some
issue with import.
While importing data, there could be a case where a new
object has to be
created which reference to some existing object. While
marshalling jibx
pulle out that object in xml file but I don't want that object to be
created while importing (as that object already exists on
target system).
I'll appreciate any help in this regard.
thanks
rohit
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_idv37&alloc_id865&op=click
_______________________________________________
jibx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jibx-users