How can I set the current schema for DB2 using Hibernate/JDBC?

Brian Deterling picture Brian Deterling · Jun 1, 2010 · Viewed 33.9k times · Source

I used to use currentSchema=MYSCHEMA; in my JDBC URL connection, but the version of DB2 we're using no longer supports that, showing the error 'The "currentSchema" property is not allowed on the target server'. I've tried using hibernate.default_schema, but it's not automatically adding the schema to my table names. I don't want to set the schema on every @Table annotation since I'll need to change it between test and production. Is there another way to set on the connection or via Hibernate?

Update: it must have been a driver version issue. I upgraded to later drivers and currentSchema worked.

Answer

Stéphane B. picture Stéphane B. · Jun 4, 2012

With DB2 JDBC type 4 driver (com.ibm.db2.jcc.DB2Driver), I'm using this URL to connect :

jdbc:db2://<HOST>:<PORT>/<DATABASE>:currentSchema=<SCHEMA>;

Source: http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/rjvdsprp.htm