I have below entity configuration
@Entity
@RestResource
public class Employee {
@Id
@GeneratedValue
@Type(type = "pg-uuid")
private UUID id;
@OneToMany(mappedBy = "employee")
@RestResource(path = "projects", rel = "projects")
private List<EmployeeToProject> projects;
}
@Entity
@RestResource
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true)
@RestResource(path = "employees", rel = "employees")
private List<EmployeeToProject> employees;
}
@Entity
@RestResource
public class EmployeeToProject {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@RestResource(path = "employee", rel = "employee")
private Employee employee;
@ManyToOne
@RestResource(path = "project", rel = "project")
private Project project;
}
And repository for EmployeeToProject with @RepositoryRestResource
to make crud apis available
@RepositoryRestResource
@CrossOrigin("*")
public interface EmployeeToProjectRepository extends PagingAndSortingRepository<EmployeeToProjectRepository, Long> {
}
I am trying to create a record in employee_to_project by using the data rest api provided
using the paths
this is giving me a numberformatexception as it is expecting a number for employee ID but I have configured employeed ID as UUID
"message": "JSON parse error: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'e21d6b85-371f-485d-ba5b-b807e2c79093'; nested exception is java.lang.NumberFormatException: For input string: \"e21d6b85-371f-485d-ba5b-b807e2c79093\"; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Failed to convert from type [java.lang.String] to type [java.lang.Long] for value 'e21d6b85-371f-485d-ba5b-b807e2c79093'; nested exception is java.lang.NumberFormatException: For input string: \"e21d6b85-371f-485d-ba5b-b807e2c79093\"
This api works if I change Emplyee ID from UUID to Long.
How I still can use UUID and utilize the data rest apis provided by Spring