hbm2ddl hibernate sql sql-server

Problem adding @ManyToOne mapping on Non primary-key in SQL Server

I have a problem with changing my spring/hibernate application from MySql to SQL Server.

When Hibernate is updating the database by starting the server he want to creates(by set on update ) the database but a foreign-key fails on following error:

Unsuccessful: alter table table2 add constraint FKDC2DC97ECEB31922 foreign key (login) references table1
Column '' is not the same data type as referencing column 'table2.table1_login' in foreign key 'FKDC2DC97ECEB31922'.

the mapping is as follows:


public String getLogin() {
return login;
public void setLogin(String login) {
this.login = login;


@JoinColumn (name = "table1_login", referencedColumnName = "login", insertable=false, updatable=false)
public Table1 getTable1() {
return table1;
public void setTable1(Table1 table1) {
this.table1= table1;

SQL looks likes this:

alt text

keys from table1:

alt text

The table table1 is also used by an other application and therefore this table needs the column ‘id’ as primary key. So is primary key of table1. But this isn’t used by hibernate, because hibernate use the table1.login as id (see annotations above). But why is SQL Server trying to set a foreign key to and not to table1.login ?