質問

I have a class which I want to persist with OrmLite and it stores most of its data in a HashMap. I want to map these fields to the table in Sqlite, leaving the ones absent in the map as null. Is it possible to override methods to save some record to the database with custom implementations using OrmLite?

役に立ちましたか?

解決

I think roddik has moved on but I thought I'd post an answer anyway as the author of OrmLite.

My general response is that it would be better to create an object to store the columns instead of a Map. Although SQL is a row of string columns, the whole point of ORM is that we can deal with the rows as objects in Java instead of a Map of strings.

@DatabaseTable
public void RandomThing {
    @DatabaseField
    String column1;
    @DatabaseField
    String column2;
    @DatabaseField
    String column3;
    public void RandomThing(String column1, String column2, String column3) {
        ...
    }
}

Right now there is not a way to persist a Map of strings in ORMLite.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top