2

I have spring boot applications which shares the same entities layer, until now the entities were duplicated among all the projects and I had test on each on the modules which worked perfectly. I extracted all the entities into a separated maven artifact and I have added dependencies from my projects to the new artifact. Everything seems to work fine except for my tests which are not able to run. I get the following error when running my tests:

Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: PIM_SECURITIES
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.SchemaManager.getTable(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.ParserDQL.readTableName(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.ParserDQL.readSimpleRangeVariable(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.ParserDML.compileInsertStatement(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.ParserCommand.compilePart(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.ParserCommand.compileStatements(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.Session.executeDirectStatement(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.Session.execute(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source) ~[hsqldb-2.2.8.jar:2.2.8]

below is the definition of my spring boot test class

@ContextConfiguration(classes = {AccountsDao.class, SecuritiesDao.class,  TasksDao.class})
@RunWith(SpringRunner.class)
@DataJpaTest
@Transactional
@ActiveProfiles("test")
public class DalLayerTests extends 
AbstractTransactionalJUnit4SpringContextTests {}

the object not found is in the entities artifact.

I have tried adding the artifact to run with the test scope in maven, but it didn't help. I have tried to add it to the annotation @ContextConfiguration(classes) but it didn't help as well.

Your help will be appreciated.

Shai Embon
  • 31
  • 5

2 Answers2

1

Hsqldb changes table name to Uppercase so, if your table name consists of the lowercase characters; the case may be the cause of the error, the following are 2 options that may provide userful:-

  1. Change the table name to uppercase.
  2. Turn it the implicit uppercase table name procedure, see here
user3442047
  • 31
  • 1
  • 4
  • I don't think its the case since the tests already worked fine, I just split the entity layer to a new maven project and added new dependency to its artifact – Shai Embon Dec 31 '17 at 10:56
  • is the table embedded? was the database created? – user3442047 Dec 31 '17 at 17:58
  • The database is created perfectly, just spring wasn't able to scan and load entities as actual entities. I found a solution for it, you can look in my answer. Thank you very much for trying to help! – Shai Embon Jan 01 '18 at 07:23
1

I finally found how to make the spring context load my entities in the test.

In production I have properties file with: entitymanager.packagesToScan=com.pim

For some reason adding the property using annotation in the test class: @TestPropertySource(properties = { "entitymanager.packagesToScan = com.pim.common"})

Didn't have any affect, and putting the following annotation in the class solved the problem:

@EntityScan(basePackages = "com.pim")

Shai Embon
  • 31
  • 5