title: detached entity passed to persist: JPA inheritance
body: <p>I have a class Bus which inherits from Vehicle. It's a JPA Single table inheritance (the discriminator column is TYPE : "B" for bus).
  When I try to persist a Bus, i get this error.
  what can be the reason? thanks</p>
  
  <pre><code>Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: org.enseirb.it307.tp.entities.VehicleStatus
      at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:139)
      at org.hibernate.internal.SessionImpl.firePersistOnFlush(SessionImpl.java:838)
      at org.hibernate.internal.SessionImpl.persistOnFlush(SessionImpl.java:831)
      at org.hibernate.engine.spi.CascadingActions$8.cascade(CascadingActions.java:357)
      at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:350)
      at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:293)
      at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
      at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:379)
      at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:319)
      at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:296)
      at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
      at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:118)
      at 
  </code></pre>
  
  <p>code causing the error :</p>
  
  <pre><code>//Bus
  Bus bus1 = BusTools.getSampleBus1();
  createdToulouseOrg.addVehicle(bus1);
  logger.info("insert Bus " + bus1);
  Vehicle createdBus1 = vehicleDao.insertVehicle(bus1);
  </code></pre>
  
  <p>the insertVehicle method uses entitymanager.persist</p>
  
  <pre><code>@Override
  public Vehicle insertVehicle(Vehicle vehicle) {
  
      entityManager.getTransaction().begin();
      entityManager.persist(vehicle);
      entityManager.getTransaction().commit();
      return vehicle;
  }
  </code></pre>