Hi folks,

I'm having trouble integrating H2 with Hibernate & PostgreSQL.  To be honest
I'm not sure this is truly an H2 issue or a Hibernate one.  The background
is that we have a rather large legacy infrastructure built around Postgres
and Hibernate.  All of our "unit" tests are really functional tests that
actually exercise Postgres.  I'm trying to change them (or at least add new
ones) so that they can talk to an H2 or HSQLDB in-memory database, both for
speed and independence from the DB.  I've been stymied by a couple of
problems.
The principal issue is that Hibernate doesn't seem to auto-generate schemas
if you use JPA-style annotations and a non-default schema.  I tried applying
a patch <http://opensource.atlassian.com/projects/hibernate/browse/HHH-1853>
suggested
in the Hibernate JIRA.  With this patch applied, I see from the H2 logging
that the schema creation is happening, but it's happening after the table
creation, which obviously doesn't work.  If I try creating my schemas
manually, it gets further along, but then it fails trying to alter
constraints on tables that haven't been created yet.  As I said, I'm really
not sure H2 is at fault here, but I'm hoping maybe someone on this forum has
some experience with this.

I'm using the following.

            String jdbcUrl =
"jdbc:h2:mem:report;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=3";
            Class.forName("org.h2.Driver");
            Connection conn = DriverManager.getConnection(jdbcUrl, "DBA",
"");
            Statement st = conn.createStatement();

            // add some mappings for postgresql types
            st.executeUpdate("CREATE domain IF NOT EXISTS IP4R AS CLOB;");
            st.executeUpdate("CREATE domain IF NOT EXISTS CIDR AS CLOB;");
            st.executeUpdate("CREATE domain IF NOT EXISTS MACADDR AS
CLOB;");
            st.close();
            conn.close();


            Configuration config = new AnnotationConfiguration().
                    addAnnotatedClass(com.example.JobMessage.class).
// my custom annotated class
                    addAnnotatedClass(com.example.Job.class).
     // my custom annotated class
                    setProperty("hibernate.dialect",
"org.hibernate.dialect.H2Dialect").
                    setProperty("hibernate.connection.driver_class",
driver).
                    setProperty("hibernate.connection.url", jdbcUrl).
                    setProperty("hibernate.connection.username", "dba").
                    setProperty("hibernate.connection.password", "").
                    setProperty("hibernate.connection.pool_size", "1").
                    setProperty("hibernate.connection.autocommit", "true").
                    setProperty("hibernate.cache.provider_class",
"org.hibernate.cache.NoCacheProvider").
                    setProperty("hibernate.hbm2ddl.auto", "create").
                    setProperty("hibernate.show_sql", "true");

            SessionFactory sessionFactory = config.buildSessionFactory();


We're using Hibernate 3.2.2.ga (patched, as per above) and
Hibernate-annotations 3.2.1.ga.  I tried this with both H2 1.1.101 and
1.0.79.   If someone could point me to a known-compatible set of versions of
all these packages, that might do the trick.  Any other help or suggestions
are welcome.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to