HSQL中缺少测试序列 [英] Missing Sequences in HSQL for testing

查看:103
本文介绍了HSQL中缺少测试序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Oracle数据库,必须在其中使用序列作为主键.由于我可以控制序列号,因此一切都很好.我的问题是我的测试.使用Spring,我创建了一个HSQL数据库并对此进行了测试.该数据库是通过查看我的所有实体而构建的.为了与Oracle一起工作,我所有的实体都指定了序列名称.问题在于,当我构造HSQL数据库时,它无法找到序列(这是我所期望的),我的测试通过了,但最终在日志中产生了很多麻烦.日志中充满了这类消息.

I have a Oracle database where I have to use sequences for the primary key. This all works well as I have control over the sequence number. My problem is with my tests. Using Spring I create an HSQL db and test against this. This database is constructed by looking at all my entities. All my entities for the sake of working with Oracle have a sequence name specified. The trouble is that when I construct the HSQL db it cannot find the sequence (which I expect) My tests pass but I end up with lots of cruft in the log. The log is filled with these sort of messages.

WARN JDBCExceptionReporter:233 - SQL Error: -5501, SQLState: 42501
ERROR JDBCExceptionReporter:234 - user lacks privilege or object not found: GENDERS_SEQ

有人知道我如何删除这些虚假错误吗?我可以让HSQL忽略序列吗?在测试中有趣的是,我可以将其插入HSQL数据库,因此它必须使用自己的内部主键生成器.

Does anyone know how I can remove these spurious errors? Can I get HSQL to ignore the sequences. Interestingly in the tests I can insert into the HSQL database so it must be using its own internal primary key generator.

关于如何从日志中删除此碎片的任何想法?

Anyone any ideas on how I can remove this cruft from the log?

谢谢

推荐答案

我通过手动创建序列作为测试脚本的一部分来解决了这个问题.这并不理想,因为我宁愿将Spring/HSQL组合起来进行设置.我的代码是:

I solved this by manually creating sequences as part of my test script. Not ideal as I would rather Spring/HSQL combination set this up. My code is:

for (String sequence : sequences) {
    entityManager.createNativeQuery("DROP SEQUENCE " + sequence + " IF EXISTS").executeUpdate();
    entityManager.createNativeQuery("CREATE SEQUENCE " + sequence + " as INTEGER").executeUpdate();
}

其中sequence是一个字符串列表,这些字符串是序列名称.

where sequences is a list of string which are the sequence name.

我使用了每个测试类的@BeforeClass方法.不理想,但确实可以解决问题

I used this is the @BeforeClass method for each test class. Not ideal but it does solve the problem

这篇关于HSQL中缺少测试序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆