• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAXB how to marshal individual items referencing each other in separate files  RSS feed

 
Marc-Antoine Ouimet
Greenhorn
Posts: 3
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to persist a list of items, each of which make reference to a parent item. That structure effectively creates a multilevel list that allows for ordering and sequential searches. Some parent item references may create cycles (a parent item whose parent is a member of its children), but marshalling those references using @XmlIDREF solves that problem within a single .xml file.


Marshalling an instance of Items works perfectly with JAXB. The problem I have is if each Item holds a lot of data and if there are many Item objects in Items, then the resulting .xml file will be inconveniently massive. If I were to edit a single Item within Items in a JavaFX program, then I don't think I should have to retrieve all of the instances of Item in RAM.

Is there a way to marshal each Item in Items in separate files while retaining the references?

A solution I saw for this problem was for Items to point to files in a repository containing all the data for each instance of Item. That way, marshalled instances of Item don't have the reference to their parent Item; the relationship between the files would be persisted in a different file altogether. That solution would not be as easily readable as having a Category with a parentCategory field, for example.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid that JAXB doesn't handle this out of the box. If you want to split your data over multiple files, you should probably write an adapter that, when you deserialize an item, populates the parent field with another item that's recursively deserialized.

However, if the data is that massive, I'm not sure why you're not using a DBMS instead of XML files.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!