Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Spring boot 1.5.10
- MongoDB 3.4.3
- Java 1.8
- public class Comment {
- @Id
- private String id;
- private String author;
- private String text;
- ... constructor, getter and setter
- public class Post {
- @Id
- private String id;
- private String author;
- private String title;
- private String text;
- private long like;
- private List<Comment> comments;
- ... constructor, getter and setter
- public interface PostRepository extends MongoRepository<Post, String> {
- }
- @SpringBootApplication
- @EnableWebMvc
- public class PostRestApplication implements CommandLineRunner{
- @Autowired
- private PostRepository postRepository;
- public static void main(String[] args) {
- SpringApplication.run(PostRestApplication.class, args);
- }
- @Override
- public void run(String... arg0) throws Exception {
- postRepository.deleteAll(); //works
- List<Comment> comments = new ArrayList<>();
- comments.add(new Comment("1", "Tom", "test"));
- postRepository.save(new Post("2", "Clark", "title",
- "test", 2, comments)); //works, write on db
- for(Post post:postRepository.findAll()){ //get error on findAll()
- System.out.println(post.toString());
- }
- }
- }
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
- at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:57) ~[spring-data-commons-1.13.10.RELEASE.jar:na]
- at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
- at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
- at com.sun.proxy.$Proxy62.findAll(Unknown Source) ~[na:na]
- at com.example.postRest.repository.impl.PostRepositoryImpl.findAll(PostRepositoryImpl.java:24) ~[classes/:na]
- ... (continue)
Add Comment
Please, Sign In to add comment