2017-10-03 4 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

私は3を持っています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"))