SQLite database implementation with list <String> as column type using ORMLite

I have a requirement when I need to store a list in a database column. List serialization might be an option, but I'm not sure if it's correct.

Also, I want to avoid creating another table to hold the list items and referencing the original table row.

I am using ORMLite for database operations.

+3


source to share


1 answer


Its concept is a foreign collection.

You need to create an entity that wraps the String. Something similar:



 @DatabaseTable
 public class Student {
     @DatabaseField(generatedId = true)
     print int id;
     @DatabaseField
     private String fname;
     @DatabaseField
     private String lname;
     @DatabaseField(foreign = true)
     private Address address;

 }
Then your Address class would have a ForeignCollection of these Student.

 @DatabaseTable
 public class Address {
     @DatabaseField(generatedId = true)
     print int id;
     @ForeignCollectionField()
     private ForeignCollection<Student> student;
 }

      

Also refer to this link, maybe it will help you.

0


source







All Articles