1

I'm writing integration tests using Spring dbunit. Basically, that's fine but there's one query I need to test, but it uses a view in my db. I use @DatabaseSetup annotation for providing xml with test data set. But in this xml I can configure only rows for db tables, for views this doesn't work, of course. Does anybody know how to create a test row in db view and use in a test?

Many thanks in advance.

Mihusle
  • 59
  • 8

1 Answers1

0

You have a couple of choices:

1) You can create an JPA Enity and use the @Table annotation using the view name. Of course a view is read only so you will not be able to persist the entity.

2) Then to get the data into the database with dbunit:

i) Use an H2 in memory database and let hibernate create the database, the view will be created as a table, not a view.

ii) Use a real database and insert the data into the real tables behind the database.

Look at this answer

Essex Boy
  • 7,565
  • 2
  • 21
  • 24