Hibernate:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException

时间:2014-08-20 11:47:40

标签: hibernate

尝试运行具有SessionFactoryAnnotationConfiguration详细信息的main方法时,我收到 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException 异常。

显示的例外是

"Caused by:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernatetutorials.student_information' doesn't exist"

其中 hibernatetutorials 是数据库的名称。

我已经尝试将 hibernate.cfg.xml 文件中的 hibernate.hbm2dll.auto 属性更改为create-drop和create。此外,我还尝试使用不同版本的hibernate运行代码(4.3和3.6.10) 但似乎没有任何工作。 ........

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
    <!-- Connecting to database -->
    <property name = "hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name = "hibernate.connection.url">jdbc:mysql://localhost:3306/hibernateTutorials</property>
    <property name = "hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name = "hibernate.connection.username">root</property>
    <property name = "hibernate.connection.password">******</property>

    <!-- disable auto commit -->
    <property name = "hibernate.connection.autocommit">false</property>

    <!-- JDBC connection pool size-->
    <property name = "connection.pool_size">1</property>

    <!-- Verbose Mode : print SQL query to console -->
    <property name = "show_sql">true</property>
    <property name = "format_sql">true</property>
    <property name = "use_sql_comments">true</property>

    <!--  -->
    <property name="hibernate.hbm2dll.auto">create</property>

    <!-- for jdbc transactions -->
    <property name = "hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

    <!-- mapping file  -->
    <mapping class="com.sanchit.hibernate.Student_Info" />
</session-factory>

2 个答案:

答案 0 :(得分:0)

我在这里看到的第一件事是在hibernate属性中输入错误。这一行

<property name="hibernate.hbm2dll.auto">create</property>

必须是

<property name="hibernate.hbm2ddl.auto">create</property>

这样就可以创建表了。

如果您希望删除旧表并再次创建:

<property name="hibernate.hbm2ddl.auto">create-drop</property>

答案 1 :(得分:0)

<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>

请务必在5MySQL之间添加Dialect