title: Populating Id column with a predefined Prefix in Hibernate
body: <p>I am working on java Web Project and have to insert user records in Table. </p>
  
  <p>There is a requirement to add prefix to the ID column value in user table which means We have to add prefix like 'user' to value generated by sequence to get final value for id column as 'user00001' which is primary key for each new record which got inserted in Table.</p>
  
  <p>I have created a sequence and DB trigger to populate the ID column when any record is inserted in DB to get above requirement satisfied. I am using Oracle 11g DB.</p>
  
  <p>In my Web application,i have to use Hibernate to do DB related tasks like insert,update</p>
  
  <p>I have following xml configuration for my Table </p>
  
  <pre><code>&lt;hibernate-mapping&gt;
  &lt;class name="UserProfile" table="USER_PROFILE"&gt;
      &lt;id name="id" type="string"&gt;
          &lt;column name="id"/&gt;
          &lt;generator class="sequence"&gt;
              &lt;param name="sequence"&gt;USER_PROFILE_SEQ&lt;/param&gt;
          &lt;/generator&gt;
      &lt;/id&gt;
      &lt;property name="firstName" type="string" column="FIRST_NAME"/&gt;
      &lt;property name="middleName" type="string" column="MIDDLE_NAME"/&gt;
      &lt;property name="lastName" type="string" column="LAST_NAME"/&gt;
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>And have created Java bean for User profile as follows</p>
  
  <pre><code>public class UserProfile {
  
  private String id;
  
  private String firstName;
  
  private String middleName;
  
  private String lastName;
  
  public UserProfile() {
      super();
  }
  
  /**
   * @return the id
   */
  public String getId() {
      return id;
  }
  
  /**
   * @param id the id to set
   */
  public void setId(String id) {
      this.id = id;
  }
  
  /**
   * @return the firstName
   */
  public String getFirstName() {
      return firstName;
  }
  
  /**
   * @param firstName the firstName to set
   */
  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }
  
  /**
   * @return the middleName
   */
  public String getMiddleName() {
      return middleName;
  }
  
  /**
   * @param middleName the middleName to set
   */
  public void setMiddleName(String middleName) {
      this.middleName = middleName;
  }
  
  /**
   * @return the lastName
   */
  public String getLastName() {
      return lastName;
  }
  
  /**
   * @param lastName the lastName to set
   */
  public void setLastName(String lastName) {
      this.lastName = lastName;
  }
  }
  </code></pre>
  
  <p>Hibernate is using the sequence which i have assigned in xml mapping and getting the value but instead of populating id column value as sequence number i want it to take value generated by DB trigger which takes sequence value and add a prefix like 'user' to it before inserting the record in table.</p>
  
  <p>So my question is how to populate Id column in hibernate with trigger generated value? As i am new to Hibernate, i downloaded latest hibernate  version 4.2.7 distribution.Any help will be greatly appreciated. </p>
  
  <p>Note : I cannot drop Triggers as its requirement from Application team.</p>