我创建了一个播放应用程序并拥有一些模型。其中一个包含一个对象集,但jpa无法创建表...
package models;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Table;
import play.db.jpa.Model;
@Entity
public class Receipt extends Model {
@ElementCollection
Set<Serving> servings;
DiningTable table;
public Receipt(Set<Serving> servings, DiningTable table) {
super();
this.servings = servings;
this.table = table;
}
}
错误是
21:20:47,323 INFO ~ Listening for HTTP on port 9000 (Waiting a first request to start) ... 21:20:51,935 INFO ~ Connected to jdbc:mysql://localhost/rms_?>useUnicode=yes&characterEncoding=UTF-8&connectionCollation=utf8_general_ci 21:20:52,827 ERROR ~ Unsuccessful: create table Receipt (id bigint not null auto_increment, >table tinyblob, primary key (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 21:20:52,827 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 'table tinyblob, >primary key (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8' at line 1 21:20:53,183 ERROR ~ Unsuccessful: alter table Receipt_Serving add index FKB18778C559F3AF16 >(Receipt_id), add constraint FKB18778C559F3AF16 foreign key (Receipt_id) references Receipt >(id) 21:20:53,183 ERROR ~ Can't create table 'rms_.#sql-731_f2' (errno: 150) 21:20:53,414 INFO ~ Application 'rms' is now started !
我该如何解决这个问题?
答案 0 :(得分:1)
table
是保留关键字。尝试使用不同的列名,方法是更改字段名称或添加:
@Column(name="diningTable")
另外,我怀疑你想让DiningTable成为一个实体而不是存储为字节码(tinyblob)。如果是这样,你应该添加一些关系注释..