Sounds to me that somehow the H2 database is being closed between the calls.
Because it's an in-memory database, that means that it'll get wiped clean.

You possibly need to open a connection in the beginning and hold it
open somehow so the database doesn't go away.


On Thu, Aug 25, 2011 at 17:20, Rick <[email protected]> wrote:
> I have some more information and context on this issue that may help
> in understanding it. For reference, I've created a sample project,
> which is available here:
>
> http://www.rickherrick.com/hbm_sample.jar
>
> This is your basic Eclipse/STS/Maven 2-type project, so just extract
> and you should be able to run:
>
> jar xf hbm_sample.jar
> cd hbm_sample
> mvn clean install
>
> When you first run it, you should get a successful build. The reason
> this works is that the class CategoryServiceTests, in the method
> testCreateCategory(), actually explicitly creates the category table
> in lines 46-48. Now delete those three lines and run again. Now you
> should get the error about which I'm curious:
>
> Tests in error:
>
> testCreateCategory(org.test.hbm_sample.services.CategoryServiceTests):
> could not insert: [org.test.hbm_sample.api.Category]; SQL [insert into
> category (event, scope, id) values (?, ?, ?)]; nested exception is
> org.hibernate.exception.SQLGrammarException: could not insert:
> [org.test.hbm_sample.api.Category]
>
> Tests run: 3, Failures: 0, Errors: 1, Skipped: 0
>
> This shows the failure to create that category table under these
> circumstances. And here's where the H2 and PostgreSQL runs diverge.
> Try changing lines 34 and 35 of the BasicPlatformTests-context.xml and
> CategoryServiceTests-context.xml configuration files to use the
> PostgreSQL data source and Hibernate properties:
>
>    <bean id="dataSource" parent="postgresqlDataSource" />
>    <bean id="hibernateProperties"
> parent="postgresqlHibernateProperties" />
>
> Note that, to use the data source as configured, you need a database
> named test owned by a user named test with the password test. You can
> just modify the PostgreSQL data source definition to use an existing
> table and user if that's easier.
>
> Now run Maven on this again and it should execute successfully,
> meaning that the same code and configuration that just failed for H2
> works properly for PostgreSQL.
>
> Now here's what's REALLY strange about it, I think. The
> BasicPlatformTests unit tests never fail, in spite of the fact that
> they're doing nearly the same thing in the testCategoryDAO() method as
> what the CategoryServiceTests.testCreateCategory() function is doing.
> They're both using the DAO to create and retrieve objects in the
> database. The primary difference that I see between them is that the
> CategoryServiceTests calls cross @Transactional boundaries, whereas
> everything in the BasicPlatformTests is within a single @Transactional
> block. That might mean that the database is getting dropped between
> the session invocations on the service, but the same behavior doesn't
> happen with PostgreSQL, which it seems like it should.
>
> If anyone has any insight or ideas on this, I'd love to hear them. We
> really want to be able to run our unit tests without having to stand
> up a test database in the build environment, but until we can
> understand why we're seeing different behavior from H2, we can't
> really do that!
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups "H2 
> Database" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/h2-database?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to