Hibernate cannot automatically create table resolution (Hibernate.hbm2ddl.auto) (tables doesn ' t exist)

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/biangren/article/details/8010018

Recently began to learn hibernate, looking at Li Gang's "Lightweight Java EE Enterprise application combat." For the first Hibernate program, I wrote down the example of the book and just changed some of the MySQL connection parameters and created a new hibernate database in MySQL, that's all. However, unexpected things happen ... After the program is written, run, error

Hibernate:insert into news_table (title, content) VALUES (?,?)
Exception in thread ' main ' org.hibernate.exception.SQLGrammarException:could not insert: [org.crazyit.app.domain.News ]

............ omitted here
caused by:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Table ' hibernate.news_table ' doesn ' t exist

............ omitted here

I had an egg ache ... This is the case, if the News_table table is built in MySQL and then run successfully, this means that the connection is definitely OK. Can not automatically build a table, Baidu Ah, meet the same problem of people, according to what they said to solve, but still no effect. CSDN also Post asked, some people say is: <propertyname= "Hibernate.hbm2ddl.auto" >update (Create) </property> This setting has a problem, should use update. Well, I bet I used the update, or I'm going to make a mistake. Some say what MySQL engine does not match for the sake of that well I dare say <property name= "Hibernate.dialect" >org.hibernate.dialect.MySQLInnoDBDialect< /property> This setting, in the MySQL configuration file ini in what engine and so on is also InnoDB (this does not know, casually say point), at that time I think the problem certainly is not here. Others say that it may be that your persistent class field is set to be a keyword, and this is even more unreliable .....

Later I thought maybe is version compatibility question, the book says is uses Hibernate3 I use is hibernate4. Okay, I'll just re-download the Hibernate3 or useless ... In this way, two days down, what all kinds of ways have tried, or reported the same mistake

Finally really can not, see the next Hibernate video tutorial, step by step follow, every detail is not spared, try Hibernate.cfg.xml and **.hbm.xml each configuration .... I finally found out.

The original configuration is as follows:

<?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" >
<session-factory>
<property name= "Hibernate.connection.driver_class" >com.mysql.jdbc.Driver</property>
<property name= "Hibernate.connection.password" >liaobin1992</property>
<property name= "Hibernate.connection.url" >jdbc:mysql://localhost:3306/hibernate</property>
<property name= "Hibernate.connection.username" >root</property>
<property name= "Hibernate.dialect" >org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name= "Hibernate.show_sql" >true</property>
<property name= "Hibernate.hbm2ddl.auto" >update</property>
<mapping resource= "Org/crazyit/app/domain/news.hbm.xml"/>
</session-factory>
Configuration after the change:

<property name= "Hibernate.dialect" >org.hibernate.dialect.MySQLInnoDBDialect</property>
To replace this line with:

<property name= "Hibernate.dialect" >org.hibernate.dialect.MySQDialect</property>

That's it, and then the whole world is quiet.

Although did not understand why do so, but finally solved the problem, or a little bit of relief ...

Who can help explain the hero's passing, why?

Hibernate cannot automatically create table resolution (Hibernate.hbm2ddl.auto) (tables doesn ' t exist)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.