Hibernate: GenerationType.IDENTITY annotation - MySql problems

Bom dia (pelo menos em Portugal)

Eu estou a ter problemas a mapear uma tabela para a minha base de dados MySql. Estou a aprender a usar o JPA, por isso estou a fazer o programa basico, HelloWorld do capitulo 2 do Livro “Java Persistence with Hibernate” O meu campo “id” da classe Message é suposto ser um auto-increment, e para isso acrescentei a anotação: @Id @GeneratedValue(strategy=GenerationType.IDENTITY). O hibernate tool hbm2dll produz a seguinte linha de código para exportar para a base de dados: MESSAGE_ID bigint generated by default as identity (start with 1). Eu creio que o MySql não suporta esta definição. Se estiver certo, como posso definir o campo id com a propriedade auto-increment para a BD MySQL? Se nao, o que estou a fazer de errado?

Agradecia ajuda de alguem!

–ms

Hibernate version:
Hibernate Core 3.2.2 GA
Hibernate EntityManager 3.2.1 GA
Hibernate Tools 3.2 beta 9

Mapping documents:
Message.java
package immoserver.persistence ;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

@Entity
@Table(name=“MESSAGES”)
public class Message implements java.io.Serializable {
//
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name=“MESSAGE_ID”, nullable = false)
private Long id;

public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}
//</editor-fold>

// <editor-fold defaultstate="collapsed" desc=" Property:   String text ">
@Column(name="TEXT")
private String text;

public String getText() {
    return text;
}
public void setText(String text) {
    this.text = text;
}
// </editor-fold>

// <editor-fold defaultstate="collapsed" desc=" N-1  Relation to Message nextMessage ">
@ManyToOne( cascade = CascadeType.ALL )
@JoinColumn(name="NEXT_MESSAGE_ID")
private Message nextMessage;

public Message getMessage() {
    return this.nextMessage;
}

public void setMessage(Message message) {
    this.nextMessage = message;
}
// </editor-fold>

}

Name and version of the database you are using:
MySql 4.0.20a

the persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?> org.hibernate.ejb.HibernatePersistence
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
        
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/immo" />
        <property name="hibernate.connection.username" value="root" />
        
        <property name="hibernate.c3p0.min_size" value="5"/>
        <property name="hibernate.c3p0.max_size" value="20"/>
        <property name="hibernate.c3p0.timeout" value="300"/>
        <property name="hibernate.c3p0.max_statements" value="50"/>
        
        <property name="hibernate.c3p0.idle_test_period" value="3000"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>           
        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
    </properties>
</persistence-unit>

The generated SQL by the hibernate tool hbm2ddl:
alter table MESSAGES
drop constraint FK131AF14C43978BD2;

drop table MESSAGES if exists;

create table MESSAGES (
    MESSAGE_ID bigint generated by default as identity (start with 1),
    TEXT varchar(255),
    NEXT_MESSAGE_ID bigint,
    primary key (MESSAGE_ID)
);

alter table MESSAGES 
    add constraint FK131AF14C43978BD2 
    foreign key (NEXT_MESSAGE_ID) 
    references MESSAGES;

Full stack trace of any exception that occurs:

alter table MESSAGES
drop constraint FK131AF14C43978BD2;

drop table MESSAGES if exists;

create table MESSAGES (
MESSAGE_ID bigint generated by default as identity (start with 1),
TEXT varchar(255),
NEXT_MESSAGE_ID bigint,
primary key (MESSAGE_ID)
);

27/Fev/2007 8:28:03 org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: Unsuccessful: create table MESSAGES (MESSAGE_ID bigint generated by default as identity (start with 1), TEXT varchar(255), NEXT_MESSAGE_ID bigint, primary key (MESSAGE_ID))
27/Fev/2007 8:28:03 org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'generated by default as identity (start with 1), TEXT varchar(2

alter table MESSAGES 
    add constraint FK131AF14C43978BD2 
    foreign key (NEXT_MESSAGE_ID) 
    references MESSAGES;

27/Fev/2007 8:28:03 org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: Unsuccessful: alter table MESSAGES add constraint FK131AF14C43978BD2 foreign key (NEXT_MESSAGE_ID) references MESSAGES
27/Fev/2007 8:28:03 org.hibernate.tool.hbm2ddl.SchemaExport create
SEVERE: Table ‘immo.messages’ doesn’t exist
27/Fev/2007 8:28:03 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
4 errors occurred while performing .
Error #1: java.sql.SQLException: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘constraint FK131AF14C43978BD2’ at line 1
Error #1: java.sql.SQLException: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ‘if exists’ at line 1
Error #1: java.sql.SQLException: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'generated by default as identity (start with 1), TEXT varchar(2
Error #1: java.sql.SQLException: Table ‘immo.messages’ doesn’t exist

já descobri o erro.

Este dialecto é para Hypersonic database and NAO mysql. Tenho que mudar para

fica ai para alguem que faça a mesmo erro roockie

–ms

Normalmente o Hibernate descobre sozinho qual o dialeto que você está utilizando, não precisa nem configurá-lo no persistence.xml

Para garantir, é bom colocar. :wink: