'java: Serialize large List with references

I have a List with 100.000 elements in it. Every of these elements contains a Hashmap, which stores many of those elements.

The calculation of the dependencies between the objects takes a very long time, so I want to serialize the result to read it fast. The elements are nodes of a graph and the elements in the hashmap are their neighbors and the edge-weights-

It is important to keep the references between the objects after deserialization, that means the elements in the hashmap must be exactly the same objects like those in my 100.000 elements list. I have tried java serialization, but I get a stackoverflowerror since the list has too many circular references. I have tried to serialize each of the elements in an extra step:

out.writeObject(o);

is called for every element in the list. But after deserialization, the hashmaps in the elements are null.

I have tried to store it into database using hibernate, but if I use

@org.hibernate.annotations.Type(
        type = "org.hibernate.type.SerializableToBlobType"
 )

The elements in my map looks the same, but are new objects.

I have created a new class which contains the key and object from my map and stored it in an extra database-table but hibernate takes forever fetching these.

Replacing the objects after deserialization with their originals takes forever, too.

Does anybody has an idea how to store this list to use it fast at anytime? I am willing to try another dataformat to store the graph. Are there some ideas? Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source