views:

32

answers:

0

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.

The hibernate annotations for my ID column are as follows:

@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;
}

This ID column of this table maps to a varchar(50), while the $SSMA_seq_SEQ_EXAMPLE_ID maps to a table with a single id column with a data type of numeric(38,0).

When I attempt an insert (by creating a Java object and persisting it), I get the following exception: com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type varchar to numeric.

Conceptually, it makes sense that a numeric(38,0) would fit into a varchar(50), but it seems that the SQL Server implicit conversion does not work in this case. Unfortunately, changing the database definition is not an option at this point in time.

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.