Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
799 views
in Technique[技术] by (71.8m points)

hibernate table does not exist error

In configuration hibernate.cfg.xml, i add <property name="hibernate.hbm2ddl.auto">create</property> Hibernate do create table automatically when i run the application. However, i remove the table from database manually by running drop table sql. Then run the hibernate application again. The exception appear

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.person' doesn't exist

only way to fix the problem is restart the Mysql database. Could anyone explain this issue for me?

this is my hibernate.cfg.xml

<hibernate-configuration>  
<session-factory>  
    <property name="hibernate.connection.driver_class">  
        com.mysql.jdbc.Driver  
    </property>  
    <property name="hibernate.connection.url">  
        jdbc:mysql://localhost/test
    </property>  
    <property name="connection.username">root</property>  
    <property name="connection.password">root</property>  
    <property name="dialect">  
        org.hibernate.dialect.MySQLDialect  
    </property>  


    <!-- Drop and re-create the database schema on startup -->
    <property name="hibernate.hbm2ddl.auto">create</property>  

    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Mapping files -->  
    <mapping resource="com/mapping/Event.hbm.xml" />  
    <mapping resource="com/mapping/Person.hbm.xml"/>
</session-factory>  

Thx

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

please change the code from:

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

to :

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

try it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...