kewpiedoll99 kewpiedoll99 - 1 year ago 91
MySQL Question

MySQLSyntaxErrorException: Table XYZ doesn't exist

I am using JPA and c3p0 and attempting to query a table and getting back a stack trace claiming that the table doesn't exist. I can open a connection to the db in, for example, DbVisualizer, and see the table there. In fact, the debug statements from my app show it is able to make a connection and test its viability. But then it is not finding the table.

15:45:53.940 [http-8080-1] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtaining JDBC connection
15:45:53.940 [http-8080-1] DEBUG c.m.v.c.i.C3P0PooledConnectionPool - Testing PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@4d687dcd] on CHECKOUT.
15:45:53.949 [http-8080-1] DEBUG c.m.v.c.i.C3P0PooledConnectionPool - Test of PooledConnection [com.mchange.v2.c3p0.impl.NewPooledConnection@4d687dcd] on CHECKOUT has SUCCEEDED.
15:45:53.950 [http-8080-1] DEBUG c.m.v.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@7930ebb [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@3e30e173)
15:45:53.950 [http-8080-1] DEBUG o.h.e.j.i.LogicalConnectionImpl - Obtained JDBC connection
15:45:53.966 [http-8080-1] DEBUG org.hibernate.SQL - select alert0_.rrdb_key as rrdb1_0_, as date0_, alert0_.hostname as hostname0_, alert0_.message as message0_, alert0_.program as program0_ from reportsDb.alerts alert0_ where (alert0_.message not like '%Anomolous%') and (alert0_.message not like '%Requeue%')
Hibernate: select alert0_.rrdb_key as rrdb1_0_, as date0_, alert0_.hostname as hostname0_, alert0_.message as message0_, alert0_.program as program0_ from reportsDb.alerts alert0_ where (alert0_.message not like '%Anomolous%') and (alert0_.message not like '%Requeue%')
15:45:54.013 [http-8080-1] DEBUG c.m.v2.c3p0.impl.NewPooledConnection - com.mchange.v2.c3p0.impl.NewPooledConnection@4d687dcd handling a throwable.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'reportsDb.alerts' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_45]
at sun.reflect.NativeConstructorAccessorImpl.newInstance( ~[na:1.6.0_45]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( ~[na:1.6.0_45]
at java.lang.reflect.Constructor.newInstance( ~[na:1.6.0_45]
at com.mysql.jdbc.Util.handleNewInstance( ~[mysql-connector-java-5.1.6.jar:na]

Here is persistence.xml (in /src/main/resources/META-INF):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="" xmlns:xsi=""
<persistence-unit name="reportsDb" transaction-type="RESOURCE_LOCAL">

A subsection of applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="" xmlns:xsi=""

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"/>

<bean id="reportsDbEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="reportsDbDataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="persistenceUnitName" value="reportsDb" />
<property name="jpaDialect" ref="jpaDialect"/>

<bean id="reportsDbDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver"/>
<!--<property name="jdbcUrl" value="jdbc:mysql://devdbrw01:3306/mexp"/>-->
<property name="jdbcUrl" value="jdbc:mysql://report101:3306/worker_events"/>
<property name="user" value="********"/>
<property name="password" value="********"/>
<property name="acquireRetryDelay" value="1000"/>
<property name="acquireRetryAttempts" value="4"/>
<property name="breakAfterAcquireFailure" value="false"/>
<property name="testConnectionOnCheckout" value="true"/>
<property name="maxConnectionAge" value="14400"/>
<property name="maxIdleTimeExcessConnections" value="1800"/>

<!-- DAOs -->
<bean id="genericReportsDbDAO" class="com.pronto.mexp.common.dal.GenericReportsDbJPADAOImpl"/>

<bean id="alertJPADAO" class="com.pronto.mexp.dal.AlertJPADAOImpl" parent="genericReportsDbDAO"/>

The thing I find suspicious is the part of the hibernate query where it tries to query
select ... from reportsDb.alerts alert0_
- how do I confirm that "reportsDb" actually stands for my data source that I spec'd in applicationContext.xml?

The entity, Alert, looks like this:

@Table(name = "alerts", catalog = "reportsDb")
public class Alert {

int rrdbKey;
String hostname = "";
String message = "";
String program = "";
Date date = new Date();

@javax.persistence.Column(name = "rrdb_key", nullable = false, insertable = false, updatable = false, length = 10, precision = 0)
public int getRrdbKey() {
return rrdbKey;

public void setRrdbKey(int rrdbKey) {
this.rrdbKey = rrdbKey;

@javax.persistence.Column(name = "hostname", nullable = false, insertable = false, updatable = false, length = 32, precision = 0)
public String getHostname() {
return hostname;

public void setHostname(String hostname) {
this.hostname = hostname;

@javax.persistence.Column(name = "message", nullable = false, insertable = false, updatable = false, length = 128, precision = 0)
public String getMessage() {
return message;

public void setMessage(String message) {
this.message = message;

@javax.persistence.Column(name = "program", nullable = true, insertable = false, updatable = false, length = 40, precision = 0)
public String getProgram() {
return program;

public void setProgram(String program) {
this.program = program;

@javax.persistence.Column(name = "date", nullable = false, insertable = false, updatable = false, length = 19, precision = 0)
public Date getDate() {
return date;

public void setDate(Date date) { = date;

Answer Source

From your entity definition, remove the "catalog = 'reportsDb'" part, since it is being used to build the query like ""select from 'reportsDb.alerts'". Mysql doesn't use catalogs, AFAIK.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download