Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA SINGLE_TABLE inheritance from two tables
    primarykey
    data
    text
    <pre><code> &lt;entity class="com.AbstractClass" access="FIELD"&gt; &lt;table name="TABLE_0"/&gt; &lt;secondary-table name="TABLE_1"&gt; &lt;primary-key-join-column name="TABLE0_REF_ID" referenced-column-name="TABLE0_ID"/&gt; &lt;/secondary-table&gt; &lt;inheritance strategy="SINGLE_TABLE"/&gt; &lt;discriminator-column name="TYPE" discriminator-type="INTEGER"/&gt; &lt;attributes&gt; &lt;id name="id"&gt; &lt;column table="TABLE_1" name="TABLE1_ID"/&gt; &lt;generated-value generator="GLOBAL_GENERATOR" strategy="SEQUENCE"/&gt; &lt;/id&gt; &lt;basic name="name"&gt; &lt;column table="TABLE1" name="NAME"/&gt; &lt;/basic&gt; &lt;/attributes&gt; &lt;/entity&gt; &lt;entity class="com.DateClass"&gt; &lt;discriminator-value&gt;2&lt;/discriminator-value&gt; &lt;attributes&gt; &lt;basic name="date"&gt; &lt;column table="TABLE_1" name="DATE"/&gt; &lt;/basic&gt; &lt;/attributes&gt; &lt;/entity&gt; </code></pre> <p>I'm using Eclipselink for JPA mapping. I have two problems:</p> <ol> <li>When I'm using exact mapping as above eclipselink generating wrong query (wrong table for primary table primary key; I think this is because primary key is in secondary table, but I, can't change this - <code>TABLE_0</code> and <code>TABLE_1</code> have different primary keys and I can not change database): <code>[EL Fine]: sql: SELECT t0.NAME t1.TABLE1_ID FROM TABLE_0 t0, TABLE_1 t1 WHERE (t1.TABLE0_REF_ID = t1.TABLE0_ID)</code></li> <li><p>To solve this problem i'v used following <code>DescriptorCustomizer</code> (I can't switch primary and secondary tables, 'cause must be in primary):</p> <pre><code>@Override public void customize(ClassDescriptor descriptor) throws Exception { descriptor.getAdditionalTablePrimaryKeyFields().clear(); descriptor.getMultipleTableForeignKeys().clear(); descriptor.addForeignKeyFieldNameForMultipleTable("TABLE_0.TABLE0_ID", "TABLE_1.TABLE0_REF_ID"); } </code></pre></li> </ol> <p>In that case query generating correctly, but i'v got list of multiple instances of the same object:</p> <pre> public class GenericDAO { ... public List getAll() { CriteriaQuery cq = em.getCriteriaBuilder().createQuery(entityClass); cq.select(cq.from(entityClass)); return em.createQuery(cq).getResultList(); } } new ClassDAO().getAll(); </pre> <p>Output:</p> <pre><code>13485751-Object_1 13485751-Object_1 13485751-Object_1 13485751-Object_1 .... </code></pre>
    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