这是我的实体类。
@Entity
public class Store implements Serializable {
private static final long serialVersionUID = 1L;
public Store() {
}
@Id
private int id;
private String code;
private String password;
private String forgetPasswordNote;
private String key;
private String ownerId;
private String storeLink;
private String activationCode;
private String name;
private String homepageUrl;
private String sessionToken;
private Date dateCreated;
private Date expireDate;
private Date lastModified;
private String nmPassword;
private String storeType;
private String premium;
private double money;
private boolean refreshed;
private String country;
private String lang;
private String varId;
private String fbPageId;
private boolean fbEnabled;
private boolean informative;
private boolean active;
private String fbEnabledBy;
private String ipAddress;
private String comments;
private float commission;
private String picasaEmail;
// all getter and setter goes here
}
这是我的控制器
@Controller
public class RegController {
@RequestMapping(value = "/create/database")
public String createDatabase(ModelMap map, HttpServletRequest request) {
Store store = new Store();
store.setId(1);
store.setCode("1");
System.out.println("test worl");
@SuppressWarnings("deprecation")
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
try {
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(store);
session.getTransaction().commit();
session.close();
} catch (Exception e) {
System.out.println(e.toString());
}
return "home";
}
}
当我运行url localhost:8080 / MyApp / create / database时,出现错误。 org.hibernate.exception.SQLGrammarException:无法执行语句
我的entites类上有保留的关键字吗?
最佳答案
我发现解决方案密钥是mysql数据库上的保留关键字,因此我只是将密钥更改为storekey,一切正常。