Spring hibernate错误OneToMany关系:错误:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中出现错误

时间:2018-02-18 14:42:32

标签: spring hibernate spring-boot

我正在努力建立一对一的关系,一场比赛有很多赛事。 当spring尝试创建此Match实体时,我收到以下错误:

  

引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:   您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   'match(id bigint not null auto_increment,date varchar(255))附近,   loser varchar(255),'第1行

这是我的Match.java

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = "id"))
public class Match {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String victor;
    private String loser;
    private String date;


    @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinTable(
            name = "matches_events",
            joinColumns = @JoinColumn(
                    name = "match_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(
                    name = "event_id", referencedColumnName = "id"))
    private Collection<Event> events;

    public Match(String victor, String loser, String date) {
        super();
        this.victor = victor;
        this.loser = loser;
        this.date = date;
    }

public Match() {
    super();
}



    public Match(String victor, String loser, String date, Collection<Event> events) {
        super();
        this.victor = victor;
        this.loser = loser;
        this.date = date;
        this.events = events;
    }

    //Getters and setters...

1 个答案:

答案 0 :(得分:1)

在mysql中,“match”是full text search的保留字。更改表的名称,或更改映射,它将正常工作。