title: SQL Server Conversion Exception: Error converting data type varchar to numeric
body: <p>I am working on a project where the goal is to convert an existing application to SQL Server. However, I am running into issues with ID generation - specifically, the conversion of data types.</p>
  
  <p>The hibernate annotations for my ID column are as follows:</p>
  
  <pre><code>@Id
  @GeneratedValue(generator="ID_GEN", strategy=GenerationType.TABLE)
  @TableGenerator(name="ID_GEN", table="[$SSMA_seq_SEQ_EXAMPLE_ID]")
  @Column(name="ID", unique="true", nullable="false")
  public String getId() {
      return this.id;
  }
  </code></pre>
  
  <p>This ID column of this table maps to a <code>varchar(50)</code>, while the <code>$SSMA_seq_SEQ_EXAMPLE_ID</code> maps to a table with a single <code>id</code> column with a data type of <code>numeric(38,0)</code>.</p>
  
  <p>When I attempt an insert (by creating a Java object and persisting it), I get the following exception: <code>com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type varchar to numeric</code>. </p>
  
  <p>Conceptually, it makes sense that a <code>numeric(38,0)</code> would fit into a <code>varchar(50)</code>, but it seems that the SQL Server <a href="http://msdn.microsoft.com/en-us/library/ms187928.aspx" rel="nofollow noreferrer">implicit conversion</a> does not work in this case. Unfortunately, changing the database definition is not an option at this point in time.</p>
  
  <p>Are there any global settings that will force this conversion in either hibernate or SQL Server? Because I am using hibernate to generate the IDs, I do not have much control over the SQL that is generated to grab an ID before committing this object to the database.</p>