Search in sources :

Example 16 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project mybatis-3 by mybatis.

the class ForEachTest method shouldNotAllowNullWhenAttributeIsFalseAndConfigurationIsTrue.

@Test
void shouldNotAllowNullWhenAttributeIsFalseAndConfigurationIsTrue() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        sqlSessionFactory.getConfiguration().setNullableOnForEach(true);
        Mapper mapper = sqlSession.getMapper(Mapper.class);
        User user = new User();
        user.setFriendList(null);
        mapper.countUserWithNullableIsFalse(user);
        Assertions.fail();
    } catch (PersistenceException e) {
        Assertions.assertEquals("The expression 'friendList' evaluated to a null value.", e.getCause().getMessage());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Example 17 with PersistenceException

use of org.apache.ibatis.exceptions.PersistenceException in project mybatis-3 by mybatis.

the class DynSqlTest method testNonValueObjectWithoutParamAnnotation.

/**
 * Variations for with https://github.com/mybatis/mybatis-3/issues/1486
 */
@Test
void testNonValueObjectWithoutParamAnnotation() {
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        DynSqlMapper mapper = sqlSession.getMapper(DynSqlMapper.class);
        DynSqlMapper.Conditions conditions = new DynSqlMapper.Conditions();
        conditions.setId(3);
        List<String> descriptions = mapper.selectDescriptionByConditions(conditions);
        assertEquals(1, descriptions.size());
        assertEquals("Pebbles", descriptions.get(0));
        assertEquals(7, mapper.selectDescriptionByConditions(null).size());
        assertEquals(7, mapper.selectDescriptionByConditions(new DynSqlMapper.Conditions()).size());
    }
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        DynSqlMapper mapper = sqlSession.getMapper(DynSqlMapper.class);
        DynSqlMapper.Conditions conditions = new DynSqlMapper.Conditions();
        conditions.setId(3);
        try {
            mapper.selectDescriptionByConditions2(conditions);
        } catch (PersistenceException e) {
            assertEquals("There is no getter for property named 'conditions' in 'class org.apache.ibatis.submitted.dynsql.DynSqlMapper$Conditions'", e.getCause().getMessage());
        }
        assertEquals(7, mapper.selectDescriptionByConditions2(null).size());
    }
    try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
        DynSqlMapper mapper = sqlSession.getMapper(DynSqlMapper.class);
        DynSqlMapper.Conditions conditions = new DynSqlMapper.Conditions();
        conditions.setId(3);
        try {
            mapper.selectDescriptionByConditions3(conditions);
        } catch (PersistenceException e) {
            assertEquals("There is no getter for property named 'conditions' in 'class org.apache.ibatis.submitted.dynsql.DynSqlMapper$Conditions'", e.getCause().getMessage());
        }
        assertEquals(7, mapper.selectDescriptionByConditions3(null).size());
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PersistenceException(org.apache.ibatis.exceptions.PersistenceException) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.jupiter.api.Test)

Aggregations

PersistenceException (org.apache.ibatis.exceptions.PersistenceException)17 BaseDataTest (org.apache.ibatis.BaseDataTest)6 Test (org.junit.jupiter.api.Test)6 Properties (java.util.Properties)5 RowBounds (org.apache.ibatis.session.RowBounds)5 SqlSession (org.apache.ibatis.session.SqlSession)5 Test (org.junit.Test)5 PropertyDefinitions (org.sonar.api.config.PropertyDefinitions)5 CorePropertyDefinitions (org.sonar.core.config.CorePropertyDefinitions)5 TaskanaRuntimeException (pro.taskana.exceptions.TaskanaRuntimeException)5 Reader (java.io.Reader)2 ArrayList (java.util.ArrayList)2 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)2 ClassificationSummary (pro.taskana.ClassificationSummary)2 Duration (java.time.Duration)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 Attachment (pro.taskana.Attachment)1 TaskSummary (pro.taskana.TaskSummary)1 WorkbasketAccessItem (pro.taskana.WorkbasketAccessItem)1 WorkbasketSummary (pro.taskana.WorkbasketSummary)1