Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can also do this without using subclasses if you use two different persistence units. </p> <p>Each persistence unit can specify a unique set of mappings (including table name). One way to achieve this is to create two orm.xml files. In persistence.xml you'll need something like this :</p> <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"&gt; &lt;persistence-unit name="mapping-1"&gt; . . . &lt;mapping-file&gt;orm-1.xml&lt;/mapping-file&gt; . . . &lt;/persistence-unit&gt; &lt;persistence-unit name="mapping-2"&gt; . . . &lt;mapping-file&gt;orm-2.xml&lt;/mapping-file&gt; . . . &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>Then within orm-1.xml : </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" version="1.0"&gt; &lt;package&gt;mypackage&lt;/package&gt; &lt;entity name="myEntity" class="myClass"&gt; &lt;table name="TABLE1"&gt; &lt;/table&gt; &lt;/entity&gt; &lt;/entity-mappings&gt; </code></pre> <p>And within orm-2.xml : </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd" version="1.0"&gt; &lt;package&gt;mypackage&lt;/package&gt; &lt;entity name="myEntity" class="myClass"&gt; &lt;table name="TABLE2"&gt; &lt;/table&gt; &lt;/entity&gt; &lt;/entity-mappings&gt; </code></pre> <p>You'll need to create a separate EntityManagerFactory for each PersistenceUnit (probably not what you want), but if you wanted to use the same class on different databases (with different table names) this would be a way to go. </p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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