Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1019525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:01:36+00:00 2026-05-16T11:01:36+00:00

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

  • 0

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 hibernate.hbm2ddl.auto 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 'table1.id' is not the same data type as referencing column 'table2.table1_login' in foreign key 'FKDC2DC97ECEB31922'.

the mapping is as follows:

table1:

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

table2:

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

++edit:
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 table1.id is primary key of table1. But this table1.id 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 table1.id and not to table1.login ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:01:37+00:00Added an answer on May 16, 2026 at 11:01 am

    Here is what the JPA specification writes about the Id annotation:

    9.1.8 Id Annotation

    The Id annotation specifies the
    primary key property or field of an
    entity. The Id annotation may be
    applied in an entity or mapped
    superclass.

    By default, the mapped column for the
    primary key of the entity is assumed
    to be the primary key of the primary
    table. If no Column annotation is
    specified, the primary key column name
    is assumed to be the name of the
    primary key property or field.

    So I’m tempted to say that things behave as per the specification (and the login property gets actually mapped on the id column). Try to specify a Column annotation:

    @Id @Column(name = "login")
    public String getLogin() {
        return login;
    }
    public void setLogin(String login) {
        this.login = login;
    }
    

    I can’t recreated the table1 because this is an excisting table. I must use the alter table option from the DLL: “alter table table2 add constraint FK1751F2B3CEB31922 foreign key (table1_login) references table1” and I rather want the referential integrity.

    To clarify, here is what Wikipedia says about foreign keys: the foreign key identifies a column or a set of columns in one (referencing) table that refers to a set of columns in another (referenced) table. The columns in the referencing table must be the primary key or other candidate key in the referenced table.

    So, while you can’t apply the above alter statement (table1_login can’t reference the id of table1, you can make login unique in table1 and create a FK constraint that would reference login. Something like that:

    ALTER TABLE table2
    ADD CONSTRAINT FK_table2_table1
    FOREIGN KEY (table1_login)
    REFERENCES table1(login)
    

    This assumes you added a UNIQUE constraint on login in table1.

    See also

    • FOREIGN KEY Constraints
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a particular problem with updating a TextBlock with changing values (which will
We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I have a problem with updating the value of property from code which is
I have the following problem. I want to call a soubroutine for changing the
I have a spring application and I want to create a unitary test on
I have some CheckBoxPreferences and I have no problem changing the icon for them
HI! I have a problem with changing the name of a select element. I
I have the following code, and i have a problem regarding changing the ringtone
I have an strange problem with sencha touch. Changing the value in the select
I have problem with show or hide form in Window Form Application. I start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.