1

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.

parml
  • 497
  • 5
  • 15
  • Possible duplicate of [Hibernate + PostgreSQL + Network Address Type (inet, cdir)](https://stackoverflow.com/questions/20019866/hibernate-postgresql-network-address-type-inet-cdir) – Pospolita Nikita Jun 26 '18 at 07:42
  • @PospolitaNikita This question is not about the custom user type `InetAddressType`. As mentioned in the question, the custom user type is working as expected. This question is about the automatic schema generation by Hibernate. Neither is the solution provided in the accepted answer available on the page you mentioned. This is not a duplicate of https://stackoverflow.com/q/20019866/1864720 – parml Jun 26 '18 at 08:31

1 Answers1

1

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

@Column(columnDefinition = "inet")
Cepr0
  • 28,144
  • 8
  • 75
  • 101