title: How do I know the id before saving an object in jpa
body: <p>I have a new object. I want to know id before saving it. Is it possible? Or there is another way for this? I am using jpa as orm and oracle as database.</p>
  
  <pre><code>@Id
  @Basic(optional = false)
  @Column(name = "ID", nullable = false)
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "woTypeSeq")
  private Long id;
  </code></pre>
  
  <p>I have a code field in my entity. If the user doesn't enter a value for the <code>code</code> field, I want to set code as entity's id. If I persist entity, of course i can get id and set code value as id, but this is extra query database.</p>
  
  <p>I want to do something like that</p>
  
  <pre><code>if(entity.getCode()==null) {
     entity.setCode(entity.getId);
     jpaDao.saveOrUpdate(entity);
  }
  </code></pre>