title: How to get Composite ID object of new persisted entity?
body: <p>I'm trying to get the (Embeddable) composite-id of an object newly persisted to the DB. I'm using mysql (myisam) with hibernate 4.3.5.</p>
  
  <p>The insert operation itself succedes, but the category-id of the created java object is always null even I flushed the object and commited the transaction.
  But this only happens with composite-id objects. In single id objects I always get the new id back.</p>
  
  <p>Did I forget something? Any help is appreciated.</p>
  
  <p>Thank you in advance</p>
  
  <p>Ben</p>
  
  <p>JUnit:</p>
  
  <pre><code>@Test
  public void _1testInsertCombinedEntity() {
      CategoryDao catDao = new CategoryDao();
  
      Category cat = new Category();
      CategoryId catId = new CategoryId();
      catId.setCategoryCustomerId(1l);
      cat.setCategoryId(catId);
  
      cat.setCategoryName(catName);
      cat.setCategoryDescr("Hello World. This is a test");
      cat.setCategoryPrintable(true);
      cat.setCategoryBookable(true);
  
      cat = catDao.save(cat);
  
      Assert.assertNotNull(cat.getCategoryId().getCategoryId());
  
  }
  </code></pre>
  
  <p>Category:</p>
  
  <pre><code>    @Entity
  @Table(name = "category")
  public class Category implements ICombinedIdEntity {
  
      @EmbeddedId
      private CategoryId categoryId;
  
   ........
  </code></pre>
  
  <p>CategoryId</p>
  
  <pre><code>@Embeddable
  public class CategoryId implements Serializable, ICombinedId&lt;Long, Long&gt; {
  
      /**
       * 
       */
      private static final long serialVersionUID = -7448052477830797280L;
  
      @Column(name = "category_id", nullable = false)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long              categoryId;
  
      @Column(name = "category_customer_id", nullable = false)
      private Long              categoryCustomerId;
  
      public Long getCategoryId() {
          return this.categoryId;
      }
  
      public void setCategoryId(Long categoryId) {
          this.categoryId = categoryId;
      }
  
      public Long getCategoryCustomerId() {
          return this.categoryCustomerId;
      }
  
      public void setCategoryCustomerId(Long categoryCustomerId) {
          this.categoryCustomerId = categoryCustomerId;
      }
  </code></pre>
  
  <p>AbstractDao save method</p>
  
  <pre><code>protected T saveEntity(T entity) {
          startTransaction();
          System.out.println("Trying to save " + entity);
          this.persistenceEngine.getEntityManager().persist(entity);
          this.persistenceEngine.getEntityManager().flush();
          commitCurrentTransaction();
          clear();
          return entity;
      }
  </code></pre>