1

I'm quite new to the subject and I'd like to know what is wrong with what I've done so far.

So to establish the database connectioin I created a persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
             xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="
        http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="Primary">
        <class>xxx.model.Lecture</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver" />
            <property name="javax.persistence.jdbc.url"    value="jdbc:db2://localhost:50000/xxx" />
            <property name="javax.persistence.jdbc.user" value="xxx" />
            <property name="javax.persistence.jdbc.password" value="xxx" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.DB2Dialect"/>
            <property name="show_sql" value="true"/>
            <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/>
        </properties>
    </persistence-unit>
</persistence>

... and included the driver .jar: db2jcc4.jar

When running the app I get the following error:

java.sql.SQLSyntaxErrorException: Schema 'DB2ADMIN' does not exist.

So did I miss something essential?

Thanks in advance!

Micromonger
  • 150
  • 10
  • Looks like you are running in Windows, with a user called db2admin. When you have a DB2 error, you should look for an error code starting with SQLXXXX where XXXX are four digits. Please try to find the SQL error, and then we can help you. Probably, you are trying to create an object in that schema, and the user does not have privileges to create in that schema. – AngocA Jun 05 '15 at 14:46

1 Answers1

2

Short Answer: you need to specify default DB schema name in persistence.xml.

…
<property name="hibernate.default_schema" value="xxx"/>
…

Explanation: Most probably you are using DB2ADMIN user to connect to the DB. The database schema name in DB2 (if not explicitly specified) is equal to user name, i.e. DB2ADMIN. Such schema doesn't exist in your DB therefore you've got the error.

You need to specify proper database schema name in JPA config, i.e. schema name where the tables are located. There is no JPA property to archive this but you are using hibernate anyway, so you can use hibernate specific property to achieve this.

Alexander Pranko
  • 1,859
  • 17
  • 20