无法执行语句SQL语法异常

问题描述 投票:0回答:1

这是我的实体类。

@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类上是否有任何保留关键字?

java hibernate entities
1个回答
2
投票

我发现解决方案密钥是mysql数据库上的保留关键字,所以我只需将密钥更改为storekey,一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.