I have a site with multiple pages, and each page has a table that contains some data. The tables have many columns, and users can select which columns to display or hide. I am trying to persist these selections.
The question I have is choosing the best way to persist these objects.
I see many possible ways, none of which Ive had success in implementing. But before I commit to one of them, I would like to know if I am doing it horribly wrong, or am way off the mark with how this should be implemented.
I have a user class that is persisted already.
Option #1 In my user entity, add a field of Map> where the key is the page name, and the list is the columns the user has selected on that page. Using @ElementCollection.
Option #2 User entity has a @onetomany List. Which requires a UserColumns entity, with pagename as primary key, and @oneToMany relationship with another entity for each column.
Option 1:
@Entity
public class User{
private Map<String, List<String>> columns;
@ElementCollection
public void setColumns(Map<String, List<String>> colunms){
}
}
Option 2:
@Entity
public class User{
private List<UserColumns> columns;
@ElementCollection or @OneToMany
public void setColumns(List<UserColumns> colunms){
}
}
I realize this will be difficult to answer without looking at the actual code, and I've probably not described the situation adequately or precisely, but welcome all input anyways. Thank you.