Search code examples
javadb4o

java - how do I save and load a list with db4o


I don't want to save the full class so I save List with this code

connection.store(myObject.getList())

And How do I load my list?

(db.query(List) doesnt work)

Thanks.


Solution

  • I would not recommend to store plain lists. The reason is that you cannot really query for a list with certain content. You only can get all lists back with (I didn't check if it works):

     // This returns all stored lists
     List<List> result = db.query(List.class);
    

    So I recommend the create a object which holds your list and query for those objects. Then it also easy to distiguish between diffrent types of list: You can create different holder classes or itroduce meta information on the holder object.

    Just another detail: db4o cannot index the content of a collection. That means queries which look if a collection contains certain members will be slow.