I am currently working on a POC for Spring Data Rest. Trying to get workable JSONout from the repository.
I have an Entity class (NewTask)
@Entity @Table(name="newtable") public class NewTask { @Id @Column(name="newid") private int id; @Column(name="newage") private int age; @Column(name="newaddress") private String address; public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
and corresponding repository.
@RepositoryRestResource @PreAuthorize("hasRole('ROLE_ADMIN')") public interface NewTaskRepository extends CrudRepository<NewTask, Serializable>{ @Query("SELECT t.address FROM NewTask t where t.id = :id") String findByMyId(@Param("id") int id); }
whenever i click
http:
I get the following error: {"cause": null, "message": "PersistentEntity must not be null!" }
Now here's what my repository looks like: read the comments for each method
//Gives- PersistentEntity must not be null!!! @Query("SELECT t.address FROM NewTask t where t.id = :id") String findByMyId(@Param("id") int id); //WORKS FINE @Query("SELECT t.id FROM NewTask t where t.id = :id") int findId(@Param("id") int id); //WORKS FINE @Query("SELECT t.id FROM NewTask t where t.id = :id") Integer findIdTwo(@Param("id") int id); //Gives- PersistentEntity must not be null!!! @Query("SELECT t.id FROM NewTask t") List<Integer> findIds();
I'm not sure what the problems are with return data types. I have provided the link below for some solution:
How to create a custom query in jparepository but return an object other than the object?
and added 2 more methods to my repository that don't work for me
// returns in some weird format @Query("SELECT t.address FROM NewTask t where t.id = :id") PString findByMyId(@Param("id") int id); //Gives- PersistentEntity must not be null!!! @Query("SELECT t.address FROM NewTask t") List<PString> findAddress();
Do I have a suspicion that this is an error in the SDR, or am I missing something?
source share