Assume there is an entity
@Entity
public class Article {
// ...
private String uri;
public void setUri(URI uri) {
this.uri = uri.toString();
}
public URI getUri() {
return URI.create(uri.toString();
}
}
and a spring data jpa repository
public interface ArticleRepository extends CrudRepository<Article, Long> {
Optional<Article> findByLink(URI link);
}
but using the findByLink(URI)
method fails with InvalidDataAccessApiUsageException: Parameter value [http://foo.de/foo.html] did not match expected type [java.lang.String (n/a)]
. This can ofcourse be avoided by changing the parameter type to string. But then every URI
has to be converted to a string before querying.
What is the best way to handle properties of type URI
if you have to query them with spring data jpa?