【发布时间】:2017-09-25 15:06:01
【问题描述】:
我在 MS SQL Server 中有一个从 Java 代码调用的用户定义函数,在 H2 数据库中运行集成测试时该函数似乎未定义。你可以在the previous question找到我的代码。
测试代码:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {H2Config.class})
@TestExecutionListeners({
DependencyInjectionTestExecutionListener.class,
DbUnitTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
@TransactionConfiguration(defaultRollback = true)
public class TableDaoTest {
@Autowired
private TableDao tableDao;
@Test
@DatabaseSetup("/datasets/import.xml")
public void testMethod01() {
tableDao.getRecordsByGroup();
...
数据库模式由 Hibernate 自动生成。如您所见,测试数据由 DbUnit 使用 xml 数据集填充。这个测试失败了,因为我在 MS SQL server DB 中存在的函数在 H2 数据库中是未定义的。
应用日志:
Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
...
Caused by: org.h2.jdbc.JdbcSQLException: Function "SAFE_MOD" not found; SQL statement:
select table10_.id, table10_.value, ... from Table1 table10_ where table10_.group1=dbo.safe_mod(?, ?);
...
如何在 DbUnit 测试前导入/创建函数?
【问题讨论】:
标签: java sql-server user-defined-functions dbunit