xing
xing

Reputation: 484

How to disable Hibernate validation of foreign key type mismatch?

I am working with an existing database. I have

Table A:
    b_id    int --> references B.id.

Table B:
    id      bigint

When I try to do a ManyToOne mapping in Class A like this:

Class A {
    @Id
    int id;

    @ManyToOne
    @JoinColumn(name="b_id")
    B b;
}

I got the following error: Found: int, expected: bigint. So I guess hibernate assumes the column A.b_id should have the same type with B.id.

The hbm2ddl is set to validate because I can not modify the database.

I've come across this answer, but it doesn't work for me. Does JPA support a @OneToMany mapping between entities without a foreign key constraint in the database?

Thanks!

Upvotes: 1

Views: 478

Answers (1)

xing
xing

Reputation: 484

Ah ha, a columnDefinition = "int" solves the problem:)

Class A {
    @Id
    int id;

    @ManyToOne
    @JoinColumn(name="b_id", columnDefinition = "int")
    B b;
}

Upvotes: 1

Related Questions