java


QueryMethodParameterConversionException


I'm trying to access JPA Data with REST using spring-boot-starter-data-rest.
I want to use a different method than the CrudRepository has. But the framework responds with the following exception:
exception is org.springframework.data.repository.support.QueryMethodParameterConversionException: Failed to convert Brazil into hello.Country!] with root cause
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [#org.springframework.data.repository.query.Param hello.Country]
Endpoint
http://localhost:8080/rest/cities/search/findByCountry?name=Brazil
CityRepository.java
#RepositoryRestResource(collectionResourceRel = "cities", path = "cities")
public interface CityRepository extends CrudRepository<City, Long> {
List<City> findByCountry(#Param("name") Country country);
}
City.java
#JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
#Entity
#Table(name = "City")
public class City implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#JsonInclude(value=Include.ALWAYS)
private long id;
#NotNull
#Column(name="name")
private String name;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "country_id")
#Embedded
private Country country;
protected City() {}
public City(long id, String nome) {
this.id = id;
this.name = nome;
}
public Country getCountry() {
return country;
}
Country.java
#JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
#Entity
public class Country implements Serializable {
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
private long id;
#NotNull
#Column(name = "name")
private String name;
#OneToMany(fetch = FetchType.LAZY, mappedBy="country")
private Set<City> cities;
protected Country() {}
public Country(long id, String nome) {
this.id = id;
this.name = nome;
}
When I call http://localhost:8080/rest/cities/ , I get the list of cities normally. I setted the configureRepositoryRestConfiguration to config.setBasePath("/rest");
java.lang.String != hello.Country
In accordance with the documentation, we need to:
Use ResponseBody with consumes
Or create object from String like in REST hello world example
I did the following to resolve this issue, using a nativeQuery:
#Query(value = "SELECT * FROM City c JOIN Country co
ON c.country_id = co.id WHERE co.name
LIKE (CONCAT_WS('%',:name, '%'))", nativeQuery = true)
List<City> country(#Param("name") String name);

Related Links

Vector vs Collections.synchronizedList(ArrayList)
Invoking a SOAP ( Web Services ) from ORACLE DB
Catching screen prints in Java
Is it possible to add JPA annotation to superclass instance variables?
JavaCC: Please give me links to “real” examples [closed]
Example of ==, equals and hashcode in java
The Java interface doesn't declare any exception. How to manage checked exceptions of the implementation?
Slow Startup for Java Web Start Application
JPA 2.0 Eclipse Link
A question in java.lang.Integer internal code
How to limit an upload speed in java servlet?
How do I fix this JBoss EJB client authentication issue?
Is -1 a magic number? An anti-pattern? A code smell? Quotes and guidelines from authorities [duplicate]
More swing design & actions
Hibernate - how to create list of pojos?
java code for converting videos into byte arrays

Categories

HOME
jdo
amazon-ec2
cookies
magnific-popup
pycharm
platform-builder
android-4.4-kitkat
youtube-dl
sqlite-net-extensions
sharepoint-designer
ojdbc
pivotal-cloud-foundry
datastax-java-driver
django-imagekit
bs4
applepay
gitpitch
nstableview
pugjs
grails3
amazonsellercentral
tapestry
realex-payments-api
devops
trading
qhull
facet
bootstrap-duallistbox
file-rename
librato
microsoft-chart-controls
socialengine
galsim
google-qpx-express-api
normal-distribution
swift3.0.2
neuroscience
webix-treetable
webdriver-manager
splice
tasker
glew
segment
btrace
wptoolkit
long-polling
jsch
flickr-api
rainbowtable
python-c-api
worksheet
pnotify
celery-task
tizen-native-app
yii2-extension
csound
typed-lambda-calculus
sqlbulkcopy
pearson
pillow
pdfclown
sonarlint-vs
gnome-shell-extensions
instant
elements
thrust
nsfilemanager
disque
persist
ubuntu-10.04
bgp
itextpdf
intel-fortran
method-parameters
nsight
sniffer
remobjects
device-orientation
umbraco6
nstableviewcell
gadt
knuth
asp.net-web-api-odata
android-radiobutton
flexmojos
sitemesh
inbox
file-locking
jplaton
back-stack
eventual-consistency
sqlperformance
type-equivalence
free-variable
itmstransporter
trusted
quickdialog
propertyeditor
pysimplesoap
boost-filesystem
php-parser
qt-jambi
subviews
coda-slider
web-application-design
mozilla-prism
mirah
asp.net-profiles
fixed-width
mtj
zend-decorators
procedural-music
gacutil
lzh

Resources

Encrypt Message