Note that there are some explanatory texts on larger screens.

plurals
  1. PO@ElementCollection or @OnetoMany with Entity or primitives?
    primarykey
    data
    text
    <p>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.</p> <p>The question I have is choosing the best way to persist these objects.</p> <p>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.</p> <p>I have a user class that is persisted already.</p> <p>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.</p> <p>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.</p> <p>Option 1:</p> <pre><code>@Entity public class User{ private Map&lt;String, List&lt;String&gt;&gt; columns; @ElementCollection public void setColumns(Map&lt;String, List&lt;String&gt;&gt; colunms){ } } </code></pre> <p>Option 2:</p> <pre><code>@Entity public class User{ private List&lt;UserColumns&gt; columns; @ElementCollection or @OneToMany public void setColumns(List&lt;UserColumns&gt; colunms){ } } </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload