An error in SQL syntax when saving data record into the database

I have an error in SQL syntax when saving data record into the database:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'option, createdBy, createdDate, updatedBy, updatedDate, description) values ('QU' at line 1
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.Util.getInstance(Util.java:381)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1031)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2362)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2280)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2265)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
    ... 86 more

In Get Session Method getSession

Struts code:

public T saveOrUpdate(T entity) {
        try {
            getSessionTx().save(entity);
            commit();
        } catch (Exception e) {
            rollback();
            e.printStackTrace();
        } finally {
            getSession().close();
        }
        return entity;
    }


    for(int i = 0;i<appendText.size();i++){
        PlayerPredictionOptionLevel2 playerPredictionOptionLevel2 = new PlayerPredictionOptionLevel2();
        playerPredictionOptionLevel2.setPlayerPredictionLevel2Id(str);
        playerPredictionOptionLevel2.setOption(appendText.get(i));
        getDaoFactory().getPlayerPredictionOptionLevel2Dao().saveOrUpdate(playerPredi‌​ctionOptionLevel2);
    }

Hibernate:

insert into expert_predictor.player_prediction_option_level2 
    (player_prediction_level2_id, option, createdBy, createdDate, updatedBy, updatedDate, description) 
  values 
    (?, ?, ?, ?, ?, ?, ?)

Entity mapping:

I have checked my entity with my DB but still there is an issue
and one thing this table have not any relationship using unique key I have managed all the code.
Please help me to solve this problem

package com.expertPredictor.model;

import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author CHiRAG
 */
@Entity
@Table(name = "player_prediction_option_level2", catalog = "expert_predictor", schema = "")
@XmlRootElement

public class PlayerPredictionOptionLevel2 implements Model {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)

    @Column(name = "player_prediction_option_level2_ID")
    private Integer playerpredictionoptionlevel2ID;


    @Column(name = "player_prediction_level2_id")
    private String playerPredictionLevel2Id;

    @Column(name = "option")
    private String option;

    @Column(name = "createdBy")
    private String createdBy;

    @Column(name = "createdDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdDate;

    @Column(name = "updatedBy")
    private String updatedBy;

    @Column(name = "updatedDate")
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedDate;

    @Column(name = "description")
    private String description;

    public PlayerPredictionOptionLevel2() {
    }

    public PlayerPredictionOptionLevel2(Integer playerpredictionoptionlevel2ID) {
        this.playerpredictionoptionlevel2ID = playerpredictionoptionlevel2ID;
    }

    public PlayerPredictionOptionLevel2(Integer playerpredictionoptionlevel2ID, String playerPredictionLevel2Id, String option, String createdBy, Date createdDate, String updatedBy, Date updatedDate) {
        this.playerpredictionoptionlevel2ID = playerpredictionoptionlevel2ID;
        this.playerPredictionLevel2Id = playerPredictionLevel2Id;
        this.option = option;
        this.createdBy = createdBy;
        this.createdDate = createdDate;
        this.updatedBy = updatedBy;
        this.updatedDate = updatedDate;
    }

    public Integer getPlayerpredictionoptionlevel2ID() {
        return playerpredictionoptionlevel2ID;
    }

    public void setPlayerpredictionoptionlevel2ID(Integer playerpredictionoptionlevel2ID) {
        this.playerpredictionoptionlevel2ID = playerpredictionoptionlevel2ID;
    }

    public String getPlayerPredictionLevel2Id() {
        return playerPredictionLevel2Id;
    }

    public void setPlayerPredictionLevel2Id(String playerPredictionLevel2Id) {
        this.playerPredictionLevel2Id = playerPredictionLevel2Id;
    }

    public String getOption() {
        return option;
    }

    public void setOption(String option) {
        this.option = option;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }

    public Date getUpdatedDate() {
        return updatedDate;
    }

    public void setUpdatedDate(Date updatedDate) {
        this.updatedDate = updatedDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (playerpredictionoptionlevel2ID != null ? playerpredictionoptionlevel2ID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PlayerPredictionOptionLevel2)) {
            return false;
        }
        PlayerPredictionOptionLevel2 other = (PlayerPredictionOptionLevel2) object;
        if ((this.playerpredictionoptionlevel2ID == null && other.playerpredictionoptionlevel2ID != null) || (this.playerpredictionoptionlevel2ID != null && !this.playerpredictionoptionlevel2ID.equals(other.playerpredictionoptionlevel2ID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.expertPredictor.model.PlayerPredictionOptionLevel2[ playerpredictionoptionlevel2ID=" + playerpredictionoptionlevel2ID + " ]";
    }

    @Override
    public EntityStatus getStatus() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void setStatus(EntityStatus status) {
        // TODO Auto-generated method stub

    }

}

13

You have SQL syntax error in the SQL generated by hibernate. The hibernate generates SQL according a dialect used by the configuration settings and it does it right, so there should not be errors if you have used HQL or criteria queries. If you are using MySQL JDBC driver then you are connecting to the MySQL database. HQL uses object mapping to get names for the tables and columns used by the query. If you are using save via hibernate session object then insert SQL statement is generated. The 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 ‘option, createdBy, createdDate, updatedBy, updatedDate, description) values (‘QU’ at line 1

shows you which column name is wrong. You can also check Reserved Words from the MySQL Reference Manual.

Usually such names can be used in the SQL if they are backquoted. For example specifying a column name as `option`. But it’s MySQL specific, and better rename it to something not reserved.

0

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật