0

So, here is my entity:

@Entity
@Table(name = "stats_search")
public class Search implements Serializable {

    /**
     * id du departement
     */
    @Id
    @GeneratedValue
    @Column(name = "stats_search_uuid")
    @Type(type="pg-uuid")
    private UUID id;

    @Column
    private Double lat;

    @Column
    private Double lng;

    @Column
    private Integer radius;

}

And its repository:

public interface StatSearchRepository extends JpaRepository<Search, UUID> {

    @Query(value = "SELECT Cast(stats_search_uuid as varchar) FROM stats_search " +
            "WHERE ip_address = :ipAddress " +
            "AND search_time > (NOW() - ((INTERVAL '1 seconds') * :delay)) " +
            "ORDER BY search_time DESC LIMIT 1",
            nativeQuery = true)
    String countByIp(String ipAddress, Integer delay);
}

My custom method returns an existing id, but when I call findById() with this id, it returns a null result.

Florent06
  • 1,008
  • 2
  • 10
  • 29
  • Do you have getters/setters and empty constructor in your entity class? It might help – Alexey Gorelik Aug 10 '21 at 19:44
  • I'm guessing that there is a problem with the java `UUID` type not being recognized as a `pg-uuid`. Try adding a `TypeDef` such as `@TypeDefs({@TypeDef(name = "pg-id-uuid", typeClass = PostgresIdUUIDType.class) })` as per [this answer](https://stackoverflow.com/a/40852415/2008394) – Erik Karlstrand Aug 10 '21 at 20:13

0 Answers0