0
votes

I have created a play application and have some models. One of them contains an object set but jpa can't create the table...

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;
    }

}

And the error is

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 !

How can I resolve this?

1

1 Answers

1
votes

table is a reserved keyword. Try using a different columname by changing the field name or by adding:

@Column(name="diningTable")

Also, I suspect you want DiningTable to be an entity and not stored as byte code (tinyblob). If so you should add some relationship annotation..