I’ve got a relatively simple class that is primarily backed by a Map<String,String>. I’d like to persist this class and be able search within the keys within the map. Based on this Stack Overflow question I get the feeling that Maps can only be persisted as a serialized blob.
I also see on the ORMLite website the following:
public class Account {
…
@ForeignCollectionField(eager = false)
ForeignCollection<Order> orders;
…
}
In the above example, the @ForeignCollectionField annotation marks
that the orders field is a collection of the orders that match the
account. The field type of orders must be either ForeignCollection
orCollection<T>– no other collections are supported. The
@ForeignCollectionField annotation supports the following fields:
Based on the above I get the impression that what I want isn’t possible, but I thought I’d check here to be sure. I have it persisted in Hibernate, but I’d rather use something lighter like ORMLite!
Yeah, there is no way in ORMLite to persist a
Map. Keeping with the KISS principle, only the simpleCollectionclass is supported.SetandMaphave a lot more interface weight to them and will probably never be supported.I don’t have any super great work arounds for you. You could obviously use
ForeignCollectionand then have a localMapfield that you create when you need to access the collection that way. Maybe anaddOrder()method that would add it to theForeignCollectionand theMap.