title: How to avoid persisting abstract data type objects as @Entity
body: <p>In JPA with EclipseLink, I'm persisting data in a product database as follows:</p>
  
  <pre><code>    em.getTransaction().begin();
      CodeArticle ca = new CodeArticle(100);
      Monnaie m = new Monnaie(2.99);
      DescriptionProduit dp = new DescriptionProduit(ca, m, "Eau minérale");
      em.persist(ca);
      em.persist(m);
      em.persist(dp);
      em.getTransaction().commit();
      em.close();
  </code></pre>
  
  <p>As you can see, the <code>Monnaie</code> and <code>CodeArticle</code> classes are simple abstract data types (ADTs). It seems overkill to make them <code>@Entity</code> elements in JPA since they can simply be converted to primitive type (e.g., <code>CodeArticle</code> is an <code>int</code>, <code>Monnaie</code> is a <code>BigInteger</code> for precise calculations, but could be a float in the database). The reason I have the classes (and not primitives) is for encapsulation of validation logic, etc. Perhaps that is reason enough to persist them as <code>@Entity</code> elements? I'm not worried about invalid XML or invalid tables (if the object passes the validation in <code>new</code> I'm assuming it's valid).</p>
  
  <p>Is there some simpler way to persist my <code>DescriptionProduit</code> objects that aggregate ADTs? I saw some examples of mapping conversions, serialization, etc., but I'm still relatively new to JPA. The closest thing to <a href="http://wiki.eclipse.org/EclipseLink/Examples/JPA/EnumToCode" rel="nofollow">mapping an ADT was with an Enum</a>, but I couldn't see how to make it work for arbitrary ADTs.</p>