parml
parml

Reputation: 649

Hibernate schema generation on PostgreSQL: wrong column type UUID instead of INET

I rely on hibernate schema generation as part of the workflow, as the changes to the model are rather big with each commit. I use the generated schema to complete the scripts used for the testing environment.

The database in use is PostgreSQL. I am using the custom postgres type INET for one of the columns (I am persisting both IPv4 and IPv6 values. I need the type check it offers.)

For that, I make use of a custom hibernate UserType (InetAddressType.java.)

In the entity, I use the hibernate specific TypeDef to register the custom UserType, and annotate the ip valued column with Type as seen in Lamp.java

@Entity
@TypeDef(name = "inet", typeClass = InetAddressType.class)
public class Lamp {
    @Type(type = "inet")
    public InetAddress getIpAddress() {
        return ipAddress;
    }

The custom user type works well with schemas generated from outside hibernate. However, when it comes to auto generation, hibernate decides that the correct type is UUID:

create table lamp (id int8 not null, ip_address uuid, primary key (id))

Is there any way to instruct hibernate to use INET instead of UUID?

Hibernate version is 5.2.17.Final.

Upvotes: 1

Views: 438

Answers (1)

Cepr0
Cepr0

Reputation: 30319

Just use @Column annotation with columnDefinition parameter, for example:

@Column(columnDefinition = "inet")

Upvotes: 1

Related Questions