Hleb
Hleb

Reputation: 295

Hibernate and MySQL throw: check the manual that corresponds to your MySQL server version for the right syntax to use near 'Show'

I'm trying to create the simplest ManyToOne relation between Film entity:

@Entity
public class Film {

    @Id
    @GeneratedValue
    private Long id;

and Show entity:

@Entity
public class Show {

    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumn(name = "film_id")
    private Film film;

I'm using MySQL database and Hibernate 4.3.0 Final. I've set up database schema auto-update on startup. And when I start this, I have such error:

ERROR: HHH000388: Unsuccessful: create table Show (id bigint not null auto_increment, price decimal(19,2), film_id bigint, primary key (id)) 14.12.2014 22:37:25 org.hibernate.tool.hbm2ddl.SchemaUpdate execute ERROR: 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 'Show (id bigint not null auto_increment, price decimal(19,2), film_id bigint, pr' at line 1 14.12.2014 22:37:25 org.hibernate.tool.hbm2ddl.SchemaUpdate execute ERROR: HHH000388: Unsuccessful: alter table Show add constraint FK_t3uhu4qn5ughklywjf8vgfjym foreign key (film_id) references Film (id) 14.12.2014 22:37:25 org.hibernate.tool.hbm2ddl.SchemaUpdate execute ERROR: 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 'Show add constraint FK_t3uhu4qn5ughklywjf8vgfjym foreign key (film_id) reference' at line 1 14.12.2014 22:37:25 org.hibernate.tool.hbm2ddl.SchemaUpdate execute

If I set FOREIGN_KEY_CHECKS = 0 to MySQL, I have same error. Where is a problem?

Upvotes: 1

Views: 764

Answers (1)

Vlad Mihalcea
Vlad Mihalcea

Reputation: 153810

Show is a reserved keyword in MySQL.

Change the associated table to FILM_SHOW and it will work:

@Entity
@Table(name="FILM_SHOW")
public class Show {
    ...
}

Upvotes: 2

Related Questions