0

I have a tabe in my database with name "Group". This is my model code:

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

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

public Group(){
    this(null,null);
}

public Group(String name, String color){
    this.name=name;
    this.color=color;
}

public int getId() {
    return id;
}

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

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getColor() {
    return color;
}

public void setColor(String color) {
    this.color = color;
}

}

I'm trying to retrieve data from database using:

     Session session=mainApp.getSessionFactory().openSession();
     groupList=FXCollections.observableArrayList(session.createCriteria(Group.class).list());
     groupPicker.setItems(groupList);
     session.close();

But it gives me an error(SQL error or missing database (near "Group": syntax error)). I know that it is happening because hibernate generates query similar to this: SELECT * FROM Group. To work properly it should be: SELECT * FROM "Group", but I do not know how to achieve this.

James_D
  • 201,275
  • 16
  • 291
  • 322
Alyona
  • 1,682
  • 2
  • 21
  • 44

2 Answers2

1

After I tried several different ways, I finally came up with a solution, which works. I just changed my model's table name to:@Table(name="\"Group\"").

Alyona
  • 1,682
  • 2
  • 21
  • 44
0

If You are using XML somehow You can be interested in element delimited-identifiers to force quoting of all entities. More can be found Hibernate, MySQL and table named "Repeat" - strange behaviour

Community
  • 1
  • 1
Chlebik
  • 646
  • 1
  • 9
  • 27