title: How to map a string to DB sequence in Hibernate
body: <p>Pretty much says it in the title. I have a class that looks something like this:</p>
  
  <pre><code>@Entity
  @Table(name="FOO")
  public class Foo {
  
    private String theId;
  
    @Id
    @Column(name = "FOO_ID")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "fooIdSeq")
    @SequenceGenerator(name = "fooIdSeq", sequenceName = "SQ_FOO_ID", allocationSize = 10)
    public String getTheId() { return theId; }
  
    public String setTheId(String theId) { this.theId = theId; }
  }
  </code></pre>
  
  <p>Using Oracle 11g, the <code>FOO_ID</code> column is a <code>VARCHAR2</code>, but the sequence <code>SQ_FOO_ID</code> yields a <code>NUMBER</code>. The database is apparently happy with this, but the application needs to be able to support non-numeric IDs that may have been inserted into this column outside of the application.</p>
  
  <p>Considering the code above, I get a <code>org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String</code>. Is there any way to do this mapping?</p>
  
  <p>Using Hibernate 3.6.</p>