Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. @Result(property = "parent", column = "parent_id", javaType = Parent.class, one = @One(select = "com.mybatis.parent.findById")),
  2.  
  3. Caused by: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
  4. ### Error querying database. Cause: java.lang.IllegalArgumentException:
  5. Mapped Statements collection does not contain value for com.mybatis.parent.findById
  6. ### The error may exist in com/mybatis/child/ChildMapper.java (best guess)
  7. ### The error may involve com.mybatis.child.ChildMapper.findById
  8. ### The error occurred while handling results
  9. ### SQL: select c.id, c.name, c.age, c.parent_id from child c where c.id = ?
  10. ### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.mybatis.parent.findById
  11.  
  12. public class Child {
  13.  
  14. private Long id;
  15.  
  16. private String name;
  17.  
  18. private Integer age;
  19.  
  20. private Parent parent;
  21.  
  22. public Child() {
  23. }
  24.  
  25. //Getters and Setters
  26.  
  27. @Mapper
  28. public interface ChildMapper {
  29.  
  30. @Select("select c.id, c.name, c.age, c.parent_id from child c where c.id = #{id}")
  31. @Results(value = {
  32. @Result(property = "parent", column = "parent_id", javaType = Parent.class, one = @One(select = "findParentById")),
  33. })
  34. Child findById(Long id);
  35.  
  36. @Select("select p.id, p.name, p.age from parent p where p.id = #{id}")
  37. Parent findParentById(Long id);
  38. }
  39.  
  40. @Repository
  41. public class ChildRepository {
  42.  
  43. private ChildMapper childMapper;
  44.  
  45. public ChildRepository(ChildMapper childMapper) {
  46. this.childMapper = childMapper;
  47. }
  48.  
  49. public Child findByid(Long id){
  50. return this.childMapper.findById(id);
  51. }
  52. }
  53.  
  54. public class Parent {
  55.  
  56. private Long id;
  57.  
  58. private String name;
  59.  
  60. private Integer age;
  61.  
  62. public Parent() {
  63. }
  64. //Getters and Setters
  65.  
  66. @Mapper
  67. public interface ParentMapper {
  68. @Select("select p.id, p.name, p.age from parent p where p.id = #{id}")
  69. Parent findById(Long id);
  70. }
  71.  
  72. @Repository
  73. public class ParentRepository {
  74.  
  75. private ParentMapper parentMapper;
  76.  
  77. public ParentRepository(ParentMapper parentMapper) {
  78. this.parentMapper = parentMapper;
  79. }
  80.  
  81. public Parent findByid(Long id){
  82. return this.parentMapper.findById(id);
  83. }
  84. }
  85.  
  86. @SpringBootApplication
  87. public class ParentChildApplication implements CommandLineRunner{
  88.  
  89. public static void main(String[] args) {
  90. SpringApplication.run(ParentChildApplication.class, args);
  91. }
  92.  
  93. @Autowired
  94. ChildRepository childRepository;
  95.  
  96. @Autowired
  97. ParentRepository parentRepository;
  98.  
  99. @Override>
  100. public void run(String... strings) throws Exception {
  101.  
  102. Child child = this.childRepository.findByid(2L);
  103.  
  104. Parent parent = this.parentRepository.findByid(1L);
  105.  
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement