Spring Data Rest (SDR ) bug? Persistent Entity Must not be null

后端 未结 3 1256
野趣味
野趣味 2020-12-19 08:07

Currently I am working on a POC for Spring Data Rest. Trying to get workable JSONout of a repository.

I have an Entity Class (NewTask)

@Entity
@Tab         


        
相关标签:
3条回答
  • 2020-12-19 08:39

    In Spring Boot, if spring main application failed to scan for your domain(POJO) classes then this error will be thrown unless you put your all classes in the same package. Then you have add component scan annotation on top of Spring main application class

    @ComponentScan(basePackages = "com.aaa.bbbb.ccccc")
    
    0 讨论(0)
  • 2020-12-19 08:48

    Spring Data REST can only return data for which the repository is registered for. In the other question that you reference, you'll notice that they created a custom repository specifically for the type that they needed. This isn't a bug in SDR, it's just how it functions. It also keeps it RESTful.

    So in your case, SDR can only return NewTask or collections of NewTask.

    0 讨论(0)
  • 2020-12-19 08:48

    I'm using Spring Data Mongo as opposed to JPA but what worked for me was including the _class field in the Mongo "select" statement. Spring uses this field to map the DB results back into an entity / document.

    Also take a look at @TypeAlias so that you have a consistent _class value as you shuffle around your domain classes.

    I also ran into the same problem when I premtively projected the DB results with Spring projections. Later when I was converting the results into paginated resources the framework could not identify the projection interface as a persistent entity and therefore could not find the necessary metadata it needed to make the conversion for me. The solution for this use case was a custom resource assembler.

    0 讨论(0)
提交回复
热议问题