1

I have a webapp that uses a database with a composite key. I need to create an API which will accept the parameters of the composite key wherein each paramenter can be null. (for eg. If all the parameters of the composite key are set as null and query is done, then it should just return all rows in db) I have used QueryByExampleExeccutor but it keeps throwing a null pointer exception.

Below is the model indicative of 1 row of the DB

public class Row
{
 @EmbeddedId
 private RowKey rowkey;

 @Column
 private String rowAttribute;

 //getters and setters for rowkey and rowAttribute

}

Below is the model indicative of RowKey

public class RowKey
{

 @Column(name = "rowBlock")
 private String rowBlock;
 @Column(name = "rowSection")
 private String rowSection;
 //getters and setters for above fields
}

I'm using QueryByExampleExecutor by extending my Repository(or DAO) with it as

public interface RowRepo extends CrudRepository<Row, RowKey>,  QueryByExampleExecutor<Row> {


}

In my service layer I use the following statement to call repo methods to return a list of matched rows from DB

 public List<Row> getRowRangeQuery(rowBlock,rowSection,rowAttribute)
 {
      Row row = new Row(new RowKey(rowBlock,rowSection),rowAttribute);
      List<Row> Result = (List<Row>)getRowRepository().findAll(Example.of(row));
      return Result;
 }

I get an InvocationTargetException which when unrolled reveals a null pointer Exception at rowSection.

hisdudeness
  • 438
  • 1
  • 5
  • 15

0 Answers0