0 Replies Latest reply: Jul 26, 2011 9:53 AM by 199225 RSS

    JPA Secondary Table vs Relationship

    199225
      I am trying to persist class cant modify it, as it was done by an external agency, and we cant change the code.

      class BaseModel{
      Long uid;

           /**
           * The change history.
           */
           private List<String> changeLog;
           /**
           * The date last modified and persisted.
           */
           private Date modificationDate;

           /**
           * The date created.
           */
           private Date creationDate;
      }

      class Article extends BaseModel{

      //other properties
      /**
      * Language code as returned by
      * Locale locale = new Locale("language code");
      * locale.toString()
      */
      String locale;
      /**
      *Text in that particular languae
      */
      String text;


      }


           <mapped-superclass class="BaseModel">
                <attributes>
                     <id name="uid">
                          <column name="UID" nullable="false" />
                          <generated-value strategy="AUTO" />
                     </id>

                     <basic name="creationDate">
                          <column name="CREATIONDATE" updatable="false" nullable="false" />
                          <temporal>TIMESTAMP</temporal>
                     </basic>
                     <basic name="modificationDate">
                          <column name="MODIFICATIONDATE" updatable="true" nullable="false" />
                          <temporal>TIMESTAMP</temporal>
                     </basic>

                     <element-collection name="changeLog">
                     </element-collection>
                </attributes>
           </mapped-superclass>


           <entity class="Article"
                name="Article " metadata-complete="true">
                <table name="Article " />
                <inheritance strategy="JOINED" />
                <secondary-table name="ArticleML">
                     <primary-key-join-column name="UID"
                          referenced-column-name="UID" />
                </secondary-table>
                <attributes>
                     <basic name="locale">
                          <column name="LOCALE" updatable="false" nullable="false" table="ArticleML"/>
                     </basic>          
                     <basic name="text">
                          <column name="TEXT" updatable="false" nullable="false" table="ArticleML"/>
                     </basic>          
                </attributes>
      </entity>

      Its creating secondary table and populating it with data, what i wanna do is;
      In secondary table create composite key made of ArticleID + AutoGenerate Primary Key for the table + locale
      And when retrieving it should retrieve based on locale.
      Its a relation in how its broken down, but from OO/JPA prespective its not, its a multilingual field.