Hello together,
I’ve a Postgres 17 DB with a Fieldtype “inet” as a Collumntype.
When I try to write a String into that field, I got an Exception, cause the type is not correct.
I use Hibernate 6.5.3
Ok, so I build an own typeclass:
public class PgInet implements Serializable {
private String address;
public PgInet() {
}
public PgInet(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
}
and the type:
public class PgInetType implements Serializable, UserType<PgInet> {
private String address = "";
public PgInetType() {
}
public PgInetType(String address) {
this.address = address;
}
public String getAddress() {
return address;
}
// more overwrite implementations...
MY entity is on:
@Entity
CbmsNetComponent
@Column(name = "\"IpAddress\"")
@Type(value = PgInetType.class)
private PgInet ipAddress;
In my Service, I create a new Entity an set the address:
netComponent.setIpAddress(new PgInet(dto.getIpAddress()));
When I want tp persist my Entity, I got:
Exception: could not execute statement [Für den Parameter 4 wurde kein Wert angegeben.] [insert into "CbmsNetComponent" ("ComponentType","Description","EnclosureId","IpAddress","IsEnabledMacDb","Modified","ComponentBaseId") values (?,?,?,?,?,?,?)]
But as you see, before I set the value.
This ist the toString output:
db.entity.CbmsNetComponent {
componentBaseId: null
componentType: 42
description:
enclosureId: 22
ipAddress: db.entity.PgInet {
address: 111.111.111.111
}
I ve no idea, what ist going wrong. Would anyone plese be so kind, and send me an idea for thas issue.
Thanks in advice, greetings Maik