Hibernate不会创建表并抛出异常

时间:2018-01-13 13:04:39

标签: java hibernate exception

我的hibernate项目有问题。 当我尝试启动简单方法时,Hibernate抛出异常:

P

我已经尝试更改我的xml配置,但它没有帮助。 这是配置:

Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at ...

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'botsender.users' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400)
at com.mysql.jdbc.Util.getInstance(Util.java:383)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:980)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3847)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3783)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2447)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)
at ...

简单的测试方法是:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
<property name="hibernate.id.new_generator_mappings">false</property>
<property name="hibernate.hbm2ddl">create</property>
    <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.password">admin12345</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/botSender</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="show_sql">true</property>
    <mapping class="com.bot.entity.User"></mapping>  
    <mapping class="com.bot.entity.Role"></mapping>  
    <mapping class="com.bot.entity.Chanel"></mapping>  
    <mapping class="com.bot.entity.MessageToChanel"></mapping>  
    <mapping class="com.bot.entity.MessageToUser"></mapping>  
    <mapping class="com.bot.entity.Status"></mapping>  
</session-factory>

我还尝试将“创建”更改为“更新”。并将“org.hibernate.dialect.MySQLDialect”更改为“MySQL5InnoDBDialect”。但我仍然陷入同样的​​例外。

0 个答案:

没有答案