多對一Hibernate自動建表問題

多對一單向關聯:User   Group

Hibernate建表不成功  報錯  :hibernate 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 'Group (id integer not null auto_increment,


原因:配置默認創建的是group表。這在mysql中應該是保留字。換個表名就OK了


做法:

@Entity
@Table(name="t_group")
public class Group 
{
private int id;

private String name;


@Id
@GeneratedValue
public int getId() {
return id;
}


public void setId(int id) {
this.id = id;
}


easy  搞定

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章