title: Mapping one DB column to two seperate fields using JPA
body: <p>I'm developing a code generator that have to generate JPA entities from database meta-model files. These model are from home-brewed modeling system which are being used to generate models other than JPA entities. </p>
  
  <p>In these models some fields are mapping back to same database column. But it seems like JPA does not like that very much. When I try to run generated code I get </p>
  
  <pre><code>Exception [EclipseLink-48] (Eclipse Persistence Services - 2.6.0.v20140809-296a69f): org.eclipse.persistence.exceptions.DescriptorException
  Exception Description: Multiple writable mappings exist for the field [FACT_INVENT_TRANS_HIST_DM.TRANSACTION_ID].  Only one may be defined as writable, all others must be specified read-only.
  Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[TransactionIdKey--&gt;FACT_INVENT_TRANS_HIST_DM.TRANSACTION_ID]
  Descriptor: RelationalDescriptor(InventTransHistFactDM --&gt; [DatabaseTable(FACT_INVENT_TRANS_HIST_DM)])
  </code></pre>
  
  <p>As I can't change the models only option left is to make one of those fields read-only. And the JPA entities being generated are only used to read data from database it will not used for writing data. Is there a way to mark some fields as read only or tell EclipseLink that these entities are read only so it does not have to worry about the multiple writable mapping. </p>
  
  <p>I tried using EclipseLink's @ReadOnly annotation in all entities but it did not help this issue.</p>