2017-05-02 21 views
0

私はHibernate 5を使ってSpringでORMを行いました。Hibernate、SQLのエラーでid列を自動的に増やすとき

私のテーブルは以下のとおりです。

public class Match { 

    @Id 
    @Column(name="match_id") 
    @GeneratedValue(strategy=GenerationType.AUTO) 
    private int id; 

    private ArrayList<String> players; 
    //@OneToMany(mappedBy="match") 
    @OneToMany(mappedBy="match") 
    private List<Game> games; 
    ... 
} 

public class Game { 

    @Id 
    @Column(name="game_id") 
    @GeneratedValue(strategy = GenerationType.AUTO) 
    private int id; 
    private String person1; 
    private String person2; 
    private String winner; 
    private int score1; 
    private int score2; 
    private int game_number; 

    @Column(name="match_id") 
    @ManyToOne(fetch=FetchType.LAZY) 
    @PrimaryKeyJoinColumn 
    private Match match; 
} 

2つのテーブル間の関係がマッチ多くのゲームが含まれているものです。

が、私は自動increasementのエラーを取得し、エラーは次のとおりです。

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'match (match_id integer not null auto_increment, players tinyblob, primary key (' at line 1 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 

エラーとinteruptがありますので、私はSQLを印刷する方法がわかりません。 私は単なるidの自動増分にエラーがあることを知らないのですか? 私はmanytoone仲間wikibooksを使用して、私の状況はEMPLOYEE(テーブル)とPHONE(テーブル)のケースに似ています。

+0

あなたはMySQL AUTO_INCREMENTカラムを使うために '@GeneratedValue(strategy = GenerationType.IDENTITY)'を試してみました。あなたはIDENTITY戦略を使用することになっています。 –

+0

SQLテーブルをどのように生成していますか? –

+0

@RajithPemabandu @GeneratedValue(strategy = GenerationType.IDENTITY)を試みましたが、同じ状況です。 – user504909

答えて

0

Matchは、MySqlの予約キーワードです。これがエラーの原因です。あなたのエンティティの名前をFootballMatchのように変更してください。

関連する問題