Problems caused by Hibernate dialect-Hibernate SQL dialect

Source: Internet
Author: User
Tags postgresql org sybase

A very strange problem was just encountered because of incorrect Hibernate SQL dialect configuration. It took some time to find out the problem.

This exception is difficult to arrange, because no exception information is thrown in the background, and the information printed in the background is normal!

Entity class:

 
Package net. yeah. fancydeepin. po;

Import javax. persistence. Column;
Import javax. persistence. Entity;
Import javax. persistence. GeneratedValue;
Import javax. persistence. Id;
Import javax. persistence. Table;
Import org. hibernate. annotations. GenericGenerator;

@ Entity
@ Table (name = "person ")
Public class Person {

Private Integer id;
Private String name;

@ Id
@ GenericGenerator (name = "idGenerator", strategy = "native ")
@ GeneratedValue (generator = "idGenerator ")
Public Integer getId (){
Return id;
}

@ Column (length = 18)
Public String getName (){
Return name;
}

Public void setId (Integer id ){
This. id = id;
}

Public void setName (String name ){
This. name = name;
}

}
 


Hibernate. cfg. xml list:

1
2 3
4 <session-factory>
5
6 <! -- Database connection settings -->
7 <property name = "connection. driver_class"> com. mysql. jdbc. Driver </property>
8 <property name = "connection. url"> jdbc: mysql: // localhost: 3306/temp </property>
9 <property name = "connection. username"> username </property>
10 <property name = "connection. password"> password </property>
11
12 <! -- SQL dialect -->
13 <property name = "dialect"> org. hibernate. dialect. SQLServerDialect </property>
14
15 <! -- Enable Hibernate's automatic session context management -->
16 <property name = "current_session_context_class"> thread </property>
17
18 <! -- Echo all executed SQL to stdout -->
19 <property name = "show_ SQL"> true </property>
20 <property name = "format_ SQL"> true </property>
21
22 <mapping class = "net. yeah. fancydeepin. po. Person"/>
23
24 </session-factory>
25
26 27


Junit test:

 
@ Test
Public void createTable (){

New SchemaExport (new AnnotationConfiguration (). configure (). create (true, true );
}
 

Background output:

 
Drop table if exists person

Create table person (
Id integer not null auto_increment,
Name varchar (18 ),
Primary key (id)
)
 

From the information output in the background, there is nothing wrong with the table creation statement, but no matter how refresh the database, there is no person table, this is depressing!

During the test, the configuration file is usually changed by Copy, which causes the problem. Let's look back at the 13th rows in the hibernate. cfg. xml list.

I realized that I had made a very low-level error. The Hibernate SQL 13th configuration is the dialect of SQL Server, and I am currently using the MySQL database. I will change this configuration line:

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

Run the Junit test again and print the same information in the background. The difference is that the person table in the database is created correctly.

Attached:

Hibernate SQL dialect (hibernate. dialect) Table

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 org. hibernate. dialect. Oracle9iDialect
Oracle 10g org. hibernate. dialect. Oracle10gDialect
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

 

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.