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());
}
}
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());
}
}
Aggregations