首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >MySQLSyntaxErrorException:表XYZ不存在

MySQLSyntaxErrorException:表XYZ不存在
EN

Stack Overflow用户
提问于 2013-04-30 04:39:28
回答 8查看 34.7K关注 0票数 8

我正在使用JPA和c3p0,并试图查询表,并返回一个堆栈跟踪,声明该表不存在。例如,我可以在DbVisualizer中打开到数据库的连接,并看到那里的表。事实上,我的应用程序的调试语句表明它能够建立连接并测试其可行性。但是,它找不到表。

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_, alert0_.date 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_, alert0_.date 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(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_45]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_45]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_45]
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) ~[mysql-connector-java-5.1.6.jar:na]
...

下面是persistence.xml (在/src/main/resources/META-INF中):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
    <persistence-unit name="reportsDb" transaction-type="RESOURCE_LOCAL">
        <description>Hibernate</description>
        <class>com.pronto.mexp.common.entity.Alert</class>
    </persistence-unit>
</persistence>

ApplicationContext.xml的一个小节:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <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" />
            </bean>
        </property>
        <property name="persistenceUnitName" value="reportsDb" />
        <property name="jpaDialect" ref="jpaDialect"/>
    </bean>

    <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"/>
    </bean>

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

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

我发现可疑的是hibernate查询中试图查询select ... from reportsDb.alerts alert0_的那一部分--我如何确认"reportsDb“实际上代表我在applicationContext.xml中指定的数据源?

ETA:实体Alert看起来像这样:

@Entity
@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)
    @Id
    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)
    @Basic
    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)
    @Basic
    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)
    @Basic
    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)
    @Basic
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}
EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2013-04-30 05:56:32

从实体定义中删除catalog = 'reportsDb'部件,因为它用于构建查询,如select from 'reportsDb.alerts'。Mysql不使用目录,AFAIK。

票数 5
EN

Stack Overflow用户

发布于 2017-01-23 03:56:39

在彻底消除代码中出现的每个表XYZ之后,我发现了实际的问题:XYZ不是由JPA引用的,而是由一个旧的、无效的mysql触发器引用的。也许可以考虑在你的代码之外寻找错误。

票数 3
EN

Stack Overflow用户

发布于 2018-06-12 04:39:26

在我的例子中,这是Hibernate将我的表转换为小写的问题。

我的错误是:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'Pluto.c_story' doesn't exist

C_Story是我的数据库,c_story是我的表(注意:不是Pluto -小写)。

我所要做的就是:

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

好吧,我希望这能帮助一些人。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16287821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档