2017-10-03 1 views
0

내가 MyBatis로 사용 앱 중에 오류를 시작했다 occures :MyBatis로 매핑 @One 주석 문제

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for pl.net.manager.dao.ProductDAO.getService() 
### The error may exist in pl/net/manager/dao/ProductDAO.java (best guess) 
### The error may involve pl.net.manager.dao.ProductDAO.getProduct 
### The error occurred while handling results 
### SQL: select * from product where id=? 
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for pl.net.manager.dao.ProductDAO.getService() 

내가 같은 테이블이 : 제품, 서비스, Rateplan

내가 세 가지를 DAO의 :

productDAO이 :

@Mapper 
public interface ProductDAO extends ServiceDAO, RateplanDAO { 

    @Select("select * from product") 
    @Results({ 
      @Result(property = "id", column = "id"), 
      @Result(property = "productStatus", column = "product_status"), 
      @Result(property = "createdBy", column = "created_by"), 
      @Result(property = "createdDate", column = "created_date"), 
      @Result(property = "modifiedBy", column = "modified_by"), 
      @Result(property = "modifiedDate", column = "modified_date"), 
      @Result(property = "service", column = "service", one = @One(select = "getService()")), 
      @Result(property = "rateplan", column = "rateplan", one = @One(select = "getRateplan()")) 
    }) 
    public List<Product> getProductList(); 

    @Select("select * from product where id=#{id}") 
    @Results({ 
      @Result(property = "id", column = "id"), 
      @Result(property = "productStatus", column = "product_status"), 
      @Result(property = "createdBy", column = "created_by"), 
      @Result(property = "createdDate", column = "created_date"), 
      @Result(property = "modifiedBy", column = "modified_by"), 
      @Result(property = "modifiedDate", column = "modified_date"), 
      @Result(property = "service", column = "service", one = @One(select = "getService()")), 
      @Result(property = "rateplan", column = "rateplan", one = @One(select = "getRateplan()")) 
    }) 
    public Product getProduct(Integer id); 
,

ServiceDAO :

@Mapper 
public interface ServiceDAO { 

    @Select("select * from service where id=#{id}") 
    @Results({ 
      @Result(property = "id", column = "id"), 
      @Result(property = "serviceStatus", column = "service_status"), 
      @Result(property = "name", column = "name"), 
      @Result(property = "createdBy", column = "created_by"), 
      @Result(property = "createdDate", column = "created_date"), 
      @Result(property = "modifiedBy", column = "modified_by"), 
      @Result(property = "modifiedDate", column = "modified_date") 
    }) 
    public Service getService(Integer id); 

RateplanDAO : 나는 제품에 대한 간단한 테스트를 썼다

@Mapper 
public interface RateplanDAO { 

    @Select("select * from rateplan where id=#{id}") 
    @Results({ 
      @Result(property = "id", column = "id"), 
      @Result(property = "name", column = "name"), 
      @Result(property = "rateplanStatus", column = "rateplan_status"), 
      @Result(property = "createdBy", column = "created_by"), 
      @Result(property = "createdDate", column = "created_date"), 
      @Result(property = "modifiedBy", column = "modified_by"), 
      @Result(property = "modifiedDate", column = "modified_date") 
    }) 
    public Rateplan getRateplan(Integer id); 

그리고 : 나는 문제가 매핑 함께 제대로 이해하고

@RunWith(SpringJUnit4ClassRunner.class) 
@ContextConfiguration(classes = MainApplication.class) 
@SpringBootTest 
public class ProductDaoTest { 

    @Autowired 
    ProductDAO productDAO; 

    @Test 
    public void getAllProductsTest(){ 
     List<Product> list = productDAO.getProductList(); 
     assertNotNull(list); 
     assertEquals(2, list.size()); 
    } 

    @Test 
    public void getSpecifiedProductTest(){ 
     Integer id =1; 
     Product product = productDAO.getProduct(id); 

     assertEquals(id, product.getId()); 

    } 
} 

하지만 따라 문서로 그것은 작동 했음에 틀림 없다. 어떻게 해결할 수있는 아이디어가 있습니까?

답변

1

당신은 @Result의 방법 이름 뒤에 괄호를 삭제해야합니다

@Result(property = "service", column = "service", one = @One(select = "getService()")) 

=>

@Result(property = "service", column = "service", one = @One(select = "getService"))