title: How to persist an entity declaring a field with a fixed-size array of a few integers using JPA/Hibernate
body: <p>I have a class with a field wich references a fixed-size array of integers:</p>
  
  <pre><code>class Tracking{
      private int[] tracks;
  }
  </code></pre>
  
  <p>What is the best way of mapping the tracks field to a database using JPA (backed by Hibernate)?</p>
  
  <p>The tracks array will contain always 10 elements. I know about @ElementCollection annotation but that implies that I'll end up with two tables (Tracking and Tracking_tracks) and it seems to be unnecessary.</p>
  
  <p>The only approach that comes to mind is to use a String field mapping the 10 numbers into a single String separated by colon. I would make that field persistent (a simple basic @Column) and then in the getters and setters I would perform the parsing into an int[].</p>
  
  <p>Any suggestions? I just want an efficient way of persisting this information. The Tracking objects will be generated permanently, there will be thousands of them and, as the number of integers is always 10, it seems overkilling to persist them into a separate table and perform joins and selects to retrieve them.</p>