Я использую данные весны jpa.i я пытаюсь реализовать функциональность поискового фильтра, используя querydsl. Если я реализую запрос querydsl без использования предложения select, я получаю правильный вывод.Когда я пытаюсь реализовать предложение select с использованием двух таблиц, я получаю JsonMappingException и HttpMessageNotWritableException.
ServiceClass :
public List<Tuple> buttonSearchClick(String sclient_acct_id,String sacct_desc,String slocation,String sinvestigator_name)
{
QAccount account=QAccount.account;
QInvestigator investigator=QInvestigator.investigator;
JPQLQuery<Tuple> query = new JPAQuery<Tuple>(entityManager);
query.select(Projections.bean(Account.class,account.sclient_acct_id,account.sacct_desc,account.slocation,
Projections.bean(Investigator.class,investigator.sinvestigator_name).as("investigator")))
.from(account);
if(sclient_acct_id!=null)
{
query.where(account.sclient_acct_id.eq(sclient_acct_id));
}
if(sacct_desc!=null)
{
query.where(account.sacct_desc.eq(sacct_desc));
}
if(slocation!=null)
{
query.where(account.slocation.eq(slocation));
}
if(sinvestigator_name!=null)
{
query.where(investigator.sinvestigator_name.eq(sinvestigator_name));
}
return query.fetch();
}
ControllerClass:
@RequestMapping(value = "/findcolumn", method = RequestMethod.GET)
public List<Tuple> searchOnClick(
@RequestParam(value = "sclient_acct_id", required = false) String sclient_acct_id,
@RequestParam(value = "sacct_desc", required = false) String sacct_desc,
@RequestParam(value = "slocation", required = false) String slocation,
@RequestParam(value = "sinvestigator_name", required = false) String sinvestigator_name) {
return testservice.buttonSearchClick(sclient_acct_id, sacct_desc,
slocation, sinvestigator_name);
}
**Console:**
Hibernate: select account0_.sclient_acct_id as col_0_0_, account0_.sacct_desc as col_1_0_, account0_.slocation as col_2_0_, investigat1_.sinvestigator_name as col_3_0_ from account account0_ cross join investigator investigat1_ where account0_.ninvestigator_id=investigat1_.ninvestigator_id
2018-12-11 17:38:05.697 WARN 5528 --- [nio-8070-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.lang.NullPointerException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: java.util.ArrayList[0]->com.example.demo.model.Account["investigator"]->com.example.demo.model.Investigator["ninst_id"])]