Glen
Glen

Reputation: 63

Play 2.0 Framework - Reserved Table Name

I have created a model called Group which in turn should create the table group. As a result the database evolutes with errors, saying the table name is a reserved word. Due to the fact that my model/table name is a reserved word I would like to know if there is a way to keep my table named group.

Here is an example of my Group model (Play Framework 2.0):

@Entity
public class Group extends Model {

@Id         private long     id;    
@Required   private String   groupName;

private static Model.Finder<Long,Group> find = 
new Model.Finder<Long,Group>   (Long.class, Group.class);

public Group() {        
}

public Group(String groupName) {
    this.groupName = groupName;
}

    /*** Getters & Setters ***/
    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }
    public String getGroupName() {
        return groupName;
    }
    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

}

Any help would be greatly appreciated!

Upvotes: 4

Views: 1046

Answers (2)

niels
niels

Reputation: 7309

Simple use

@Entity
@Table(name="groupOfxxx")
public class Group {

Something which describes the table without a reserved word.

Upvotes: 2

maialithar
maialithar

Reputation: 3123

Maybe this will help:

@Entity
@Table(name="`group`")
public class Group {

If not, try:

@Entity
@Table(name="group")
public class Group {

If not, try:

https://stackoverflow.com/a/1565765/952046

EDIT

MySQL docs says:

Most of the words in the table are forbidden by standard SQL as column or table names (for example, GROUP).

Furthermore:

The identifier quote character is the backtick (“`”):

mysql> SELECT * FROM `select` WHERE `select`.id > 100;

So it should work. Maybe there's sth wrong with quotes - make sure you use tick mark (\``), not a single quote ('). You can also try settingmysql> SET sql_mode='ANSI_QUOTES';. Check if you can create table namedgroup` from MySQL console.

Upvotes: 1

Related Questions