I looked in many places and found that hibernation with postgresql can use the IDENTITY primary key generator, which appears in the column of the serial / bigserial table. Suppose I have an entity:
@Entity
class A {
long id;
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
public long getId() { return id; }
}
Works fine, and ddl looks like this:
create table A (id bigserial)
Unfortunately, any attempt to reference 'a' via @ManyToOne creates a foreign key column, which is also large.
@Entity
class B {
A a;
@ManyToOne
public A getA() {
return a;
}
}
generates ddl as shown below:
create table B (..., a_id bigserial)
In most cases this will work fine. But logically this is completely wrong. a_id has nothing to do with the syntactic "data type".
Is there any way to tell hibernate to use bigint for the a_id column in table B?
columnDefinition @JoinColumn @Column . Hibernate .