eclipse-ee4j / eclipselink

Eclipselink project
https://eclipse.dev/eclipselink/
Other
196 stars 167 forks source link

UUIDs fail with EclipseLink and Postgres #2190

Open anija-anil opened 2 months ago

anija-anil commented 2 months ago

When creating a query with a UUID, the parameter is set as a VARCHAR instead of a UUID, and is rejected by Postgres.

Here is an example of the failing query:

UUID uuid = p1.id;
List<?> result = em.createQuery("SELECT p FROM PurchaseOrder p WHERE p.id=?1")
                   .setParameter(1, uuid).getResultList();
mswatosh commented 1 month ago

There is some discussion on how to convert to a UUID in postgres here: https://stackoverflow.com/questions/12771737/conversion-string-to-uuid-in-postgres-and-java/34652560#34652560

There is a recreate here: https://github.com/mswatosh/persistence-recreates/blob/1a2658d4e90ce56807bf7ecbc65455d1b8600f17/src/main/java/com/example/application/PersistenceService.java#L119