I want to use binary UUID in a MariaDB database used for a spring-boot project, instead of using varchar uuid. For now, I am able to create, save and search a binary UUID, by override the column length to 16 but I have to manually put the annotation @Column(length=16) on any UUID field.
Is there a way to globally made this modification in the project ? In other words, is there a way that, for all UUID field in the project, jpa/hibernate create a column "binary(16)" instead of "binary(255)" ?
My problem is that, by default, an UUID is converted into a binary(255) into MariaDB, and with this configuration, JPA Repositories queries are not able to find any data when searching on a UUID field.
To achieve Jpa repositories queries, I have to add the @Column(length=16) on any UUID field.
I have tried to use a "@Converter" but the Convert annotation should not be used to specify conversion of the following: Id attributes, version attributes, relationship attributes etc... And it doesn't work with an uuid relationship field.
I have also tried to use my own custom hibernate type (example here : https://www.maxenglander.com/2017/09/01/optimized-uuid-with-hibernate.html) but the jpa repositories queries don't find anything.
Now i have this : My abstract entity :
public abstract class GenericEntity {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
@Column(length = 16)
private UUID id;
//...
}
When using an uuid in another object :
public abstract class AnotherEntity extends GenericEntity {
@NotNull
@Column(length = 16)
private UUID owner;
//...
}
I'm looking for a way to override the UUID field generation without putting the "@Column(length = 16)" everywhere.
It would be really great to avoid errors and / or omissions when using the UUID type in others features.
Thanks a lot !