title: Hibernate move records between tables
body: <p>I need to handle approving records and making them avaialble based on their status.  My original idea was to use a flag column to filter the records but business practices of strict segregation of approved / unapproved records prevents this approach.   The next most logical approach (to me) would be to move the records to an approved table.  </p>
  
  <p>I am using the entity-name attribute to map the same class to two different tables - APPROVED_ and UNAPPROVED_.  When I try to move the record it deletes from the unapproved but does not insert into approved.  I turned on hibernate.show_sql and the retrieves / deletes are shown but no insert.</p>
  
  <p>The approved table has  generator class="assigned" so that it uses the id from the unapproved table as its key.</p>
  
  <p>Any suggestions on what I'm not doing correctly?  Or a better way to do this?</p>
  
  <p>Here is the code</p>
  
  <pre><code>    try {
          // begin transaction
          ses = Activator.getSession();
          ses.beginTransaction();
          dao.setSession(ses);
          daoMotor.setSession(ses);
  
          // for each input record in selectedMotors
          for (Long curId : selectedMotors) {
              // retrieve the input record
              IThreePhaseMotorInput record = dao.findById(curId, false);
  
              // save the motor into the permanent table using entity-name
              IThreePhaseMotor curMotor = record.getMotor();
              daoMotor.makePersistent("ThreePhaseMotor", (ThreePhaseMotor) curMotor);
  
              // delete the input record
              dao.makeTransient((ThreePhaseMotorInput) record);
          }
  
          // commit transaction
          ses.getTransaction().commit();
      } catch (Throwable t) {
          ErrorInfo info = ErrorInfoFactory.getUnknownDatabaseInfo(t, null, IThreePhaseMotorList.class.getName());
          Platform.getLog(Activator.getContext().getBundle()).log(
                  new Status(IStatus.ERROR, Activator.PLUGIN_ID, info.getErrorDescription(), t));
          throw new BusinessException(info);
      } finally {
          if (ses != null &amp;&amp; ses.isOpen()) {
              ses.close();
          }
      }
  </code></pre>
  
  <p>And the abbreviated hbm.xml files:</p>
  
  <pre><code>&lt;class name="ThreePhaseMotorInput" table="THREE_PHASE_MOTOR_INPUT" lazy="false"&gt;
      &lt;id name="id" type="java.lang.Long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;version generated="never" name="version" type="java.lang.Integer" /&gt;
      &lt;many-to-one name="motor" cascade="all" entity-name="UnapprovedThreePhaseMotor"  fetch="join"&gt;
          &lt;column name="MOTOR" /&gt;
      &lt;/many-to-one&gt;
  &lt;/class&gt;
  &lt;class name="ThreePhaseMotor" table="UNAPPROVED_THREE_PHASE_MOTOR" entity-name="UnapprovedThreePhaseMotor"&gt;
      &lt;id name="id" type="java.lang.Long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;version generated="never" name="version" type="java.lang.Integer" /&gt;
  &lt;/class&gt;
  &lt;class name="ThreePhaseMotor" table="THREE_PHASE_MOTOR"  entity-name="ApprovedThreePhaseMotor"&gt;
      &lt;id name="id" type="java.lang.Long"&gt;
          &lt;column name="ID" /&gt;
          &lt;generator class="assigned" /&gt;
      &lt;/id&gt;
      &lt;version generated="never" name="version" type="java.lang.Integer" /&gt;
  </code></pre>
  
  <p></p>