Go Hibernate cannot automatically create table solutions and hibernate different database connections and SQL dialect

Source: Internet
Author: User
Tags db2 sybase table definition advantage

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 pair 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.MySQLDialect</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?
The reasons are as follows:

This article describes the connection of different hibernate databases and the SQL dialect. Hibernate connections to different databases can cause errors, in one case because hibernate SQL dialect settings are incorrect.
If the following error occurs, the Hibernate SQL dialect (hibernate.dialect) setting may be incorrect.

caused by:java.sql.SQLException: [Microsoft][sqlserver Driver for Jdbc][sqlserver] ' last_insert_id ' is not recognizable The function name.



First, Hibernate's dialect

RDBMS dialect
DB2 Org.hibernate.dialect.DB2Dialect
DB2 as/400 Org.hibernate.dialect.DB2400Dialect
DB2 OS390 Org.hibernate.dialect.DB2390Dialect
PostgreSQL Org.hibernate.dialect.PostgreSQLDialect
Mysql Org.hibernate.dialect.MySQLDialect
MySQL with InnoDB Org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM Org.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version) Org.hibernate.dialect.OracleDialect
Oracle 9i/10g Org.hibernate.dialect.Oracle9Dialect
Sybase Org.hibernate.dialect.SybaseDialect
Sybase Anywhere Org.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Server Org.hibernate.dialect.SQLServerDialect
SAP DB Org.hibernate.dialect.SAPDBDialect
Informix Org.hibernate.dialect.InformixDialect
Hypersonicsql Org.hibernate.dialect.HSQLDialect
Ingres Org.hibernate.dialect.IngresDialect
Progress Org.hibernate.dialect.ProgressDialect
Mckoi SQL Org.hibernate.dialect.MckoiDialect
Interbase Org.hibernate.dialect.InterbaseDialect
Pointbase Org.hibernate.dialect.PointbaseDialect
Frontbase Org.hibernate.dialect.FrontbaseDialect
Firebird Org.hibernate.dialect.FirebirdDialect

ii. differences in Mysql:innodb and MyISAM

(Note: Mysqlinnodbdialect and mysqlmyisamdialect inherit from Mysqldialect.) )

InnoDB and MyISAM are two of the most important data storage engines for MySQL, both of which can be used to store tables and indexes, each with its pros and cons, depending on the application. The basic difference is that the MyISAM type does not support advanced processing such as transaction processing, and InnoDB type support. The MyISAM type of table emphasizes performance, which is performed more quickly than the InnoDB type, but does not provide transactional support, while InnoDB provides advanced database functionality such as transactional support and external keys.





InnoDB provides MySQL with transactional (commit), rollback (rollback), and crash-repair capabilities (crash recovery capabilities), multi-version concurrency control (multi-versioned concurrency control) transaction security (Transaction-safe (ACID compliant)) type table. The InnoDB provides row-level locks (locking on row levels) that provide similar non-lock reads as Oracle (non-locking
read in selects). InnoDB locks the row-level and also provides an Oracle-style, non-locking read in the SELECT statement. In addition, the INNODB is designed for maximum performance when dealing with large amounts of data. Its CPU efficiency may be unmatched by any other disk-based relational database engine. Mysqlinnodbdialect is based on the same functionality as InnoDB.



The InnoDB storage engine is fully integrated with the MySQL server, and the InnoDB storage engine maintains its own buffer pool to cache data and indexes in main memory. InnoDB stores its table and index in a table space, a tablespace can contain several files (or raw disk partitions). This is different from the MyISAM table, such as in the MyISAM table where each table is in a separate file. The InnoDB table can be any size, even if the file size is limited to 2GB on the operating system.



InnoDB is transaction-safe. It has the same characteristics as the BDB type, and they also support foreign keys. The InnoDB table is fast. Has a richer feature than BDB, so it is recommended if you need a transaction-safe storage engine. If your data performs a large number of inserts or update, you should use the InnoDB table for performance reasons.

InnoDB up-to-date information can be found on http://www.innodb.com/. InnoDB
the latest version of the manual is always placed there, and there can be a commercial license for InnoDB (Order commercial licenses) as well as support.

MyISAM is the MySQL default storage engine. Each myisam is stored as three files on disk. The first file name begins with the name of the table, and the extension indicates the file type. frm file stores the table definition. The data file has an extension of. MYD (MYData). The extension of the index file is. MYI (Myindex).

MyISAM based on the traditional ISAM type, ISAM is an abbreviation for indexed sequential access method, which has indexed sequential access methods, which is the standard way to store records and files. Compared to other storage engines, MyISAM has most of the tools for checking and repairing tables. MyISAM tables can be compressed, and they support full-text search. They are not transaction-safe and do not support foreign keys. If the rollback of a thing causes incomplete rollback, it does not have atomicity. If executing a lot of select,myisam is a better choice.

Myiasm is a new version of the Iasm table, with the following extensions:

• Portability at the binary level.

• NULL column index.

• Less fragmentation of the variable-length line than the ISAM table.

• Support for large files.

• Better index compression.

• Better key-code statistical distributions.

• Better and faster auto_increment processing.

The following is a known difference between the two, for informational purposes only.

1.InnoDB does not support indexes of type Fulltext.

The exact number of rows in the table is not saved in 2.InnoDB, that is, when you execute select COUNT (*) from table, InnoDB scans the entire table to calculate how many rows, but MyISAM simply reads the saved rows. Note that when the COUNT (*) statement contains a where condition, the operation of the two tables is the same.

3. For a field of type auto_increment, InnoDB must contain only the index of that field, but in the MyISAM table, you can establish a federated index with other fields.

4.DELETE from table, InnoDB does not reestablish the table, but deletes one row at a time.

5.LOAD table from master operation does not work for InnoDB, the solution is to first change the InnoDB table to MyISAM table, import data and then change to InnoDB table, However, tables that use additional InnoDB attributes, such as foreign keys, do not apply.

In addition, the row lock of the InnoDB table is not absolute, and if MySQL cannot determine the scope to scan when executing an SQL statement, the InnoDB table also locks the full table, such as the Update table set num=1 where name like "%aaa%".

any kind of table is not omnipotent, only appropriate for the business type to choose the appropriate table type, to maximize the performance advantage of MySQL.

attached: Two other storage engines for MySQL, memory and merge

the memory storage engine creates a table using the contents of the existing memories. Each memory meter only actually corresponds to one disk file. Memory Type table access is very fast because its data is placed in memory, and the hash index is used by default. But once the service is closed, the data in the table is lost.

The merge storage engine is a combination of a set of MyISAM tables that must be structured exactly the same as the MyISAM tables. The merge table itself has no data, and the query, update, and delete operations on the merge type table are performed on the internal MyISAM table.

Memory type of storage engine is mainly used in those with less frequent changes in the Code table, or as a statistical operation of the intermediate results table, easy to efficiently analyze the heap intermediate results and get the final statistical results. It is prudent to update the tables of the memory storage engine because the data is not actually written to disk, so be sure to consider how to obtain the modified data after the next service restart.

The merge is used to logically group together a series of equivalent MyISAM tables and reference it as an object. The advantage of the merge table is that it can break the limit on the size of a single MyISAM table, and it can effectively improve the access efficiency of the merge table by distributing different tables on multiple disks.

Original Source:
http://blog.csdn.net/biangren/article/details/8010018
http://blog.csdn.net/moonsheep_liu/article/details/6416546

Go Hibernate cannot automatically create table solutions and hibernate different database connections and SQL dialect

Related Article

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.