Getting below error while trying to retrieve data via redis cache:- Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.List com.concretepage.CelebController.getAll()] caches=[celebcache] | key='#p1' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'] with root cause
Have tried solution from other problems of similar types by renaming the cachekey to #p0 but still facing the same error.
Model:-
import javax.persistence.*;
@Entity(name="celeb")
public class Celeb {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private long id;
@Column(name="celeb_name")
private String name;
@Column(name="no_of_followers")
private long followers;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public long getFollowers() {
return followers;
}
public void setFollowers(long followers) {
this.followers = followers;
}
@Override
public String toString() {
return "Celeb{" +
"id=" + id +
", name='" + name + '\'' +
", followers=" + followers +
'}';
}
}
Model Controller:-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
public class CelebController {
Logger logger = LoggerFactory.getLogger("CelebController");
@Autowired
private CelebRepository celebRepository;
@PostMapping("/create")
public void createUser(@RequestBody Celeb user) {
celebRepository.save(user);
}
@Cacheable(value = "celebcache", key = "#p0")
@GetMapping("/getall")
public List<Celeb> getAll() {
logger.info("Returning from DB");
return celebRepository.findAll();
}
@PostMapping("/delete")
public void createUser(@RequestParam(value = "userid")Integer id) {
celebRepository.deleteById(id);
}
}