在我数据库里有test数据库,其中有一人user表,用hibernate映射到User类,配置时URL为:jdbc:mysql://localhost:3306/test
但发布运行后有错误:如下:
Hibernate operation: could not execute query; bad SQL grammar [select user0_.id as id, user0_.username as username0_, user0_.password as password0_ from test__user user0_ where username=?]; Table 'test.test__user' doesn't exist这错误中表怎么变成test__user了,明明我数据库表名是user,郁闷了。不知道为什么,请教一下。

解决方案 »

  1.   

    那要看你的hibernate配置文件是怎么配置的!
      

  2.   

    我是直接在spring中配置的
    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName">
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
    <value>jdbc:mysql://localhost:3306/test</value>
    </property>
    <property name="username">
    <value>root</value>
    </property>
    <property name="password">
    <value>root</value>
    </property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/web/bo/User.hbm.xml</value></list>
    </property></bean>
      

  3.   

    把你的user表映射User的xml文件里面的:table="test.test__user" 改成"user";
      

  4.   

    没有呀,我user.bhm.xml是这样的:
    hibernate-mapping>
        <class name="com.web.bo.User" table="user" catalog="test">
            <id name="id" type="integer">
                <column name="id" />
                <generator class="native" />
            </id>
            <property name="username" type="string">
                <column name="username" length="20" not-null="true" />
            </property>
            <property name="password" type="string">
                <column name="password" />
            </property>
        </class>
    </hibernate-mapping>
      

  5.   

    如何解决的?难道你的JNDI定义的时候把表的名字写成了test__user?
    也让我们学习一下啊。呵呵。
      

  6.   

    user.bhm.xml文件中
    <class name="com.web.bo.User" table="user" catalog="test">把自动生成的catalog="test"删掉!!!