简体   繁体   English

org.hibernate.exception.GenericJDBCException:无法插入:

[英]org.hibernate.exception.GenericJDBCException: could not insert:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.annotations.Version).
log4j:WARN Please initialize the log4j system properly.
Hibernate: insert into purchase_details (date, total_quantity, total_weight, type) values (?, ?, ?, ?)
HE:org.hibernate.exception.GenericJDBCException: could not insert: [com.focus.beans.PurchaseDetailsList]

Table created but the values are not inserted into the tables... How can i solve this? 已创建表格,但未将值插入表格中...我该如何解决? Please help me. 请帮我。

    package com.focus.beans;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;



@Entity
@Table(name = "purchase_details")
public class PurchaseDetailsList {
    @Id @GeneratedValue
    @Column (name="type_id")
    @Getter @Setter private String type_id;

    @Column (name = "type")
    @Getter @Setter private String type; 

    @Column(name = "date")
    @Getter @Setter private String date;

    @Column (name = "total_quantity")
    @Getter @Setter private String totalquantity;

    @Column (name = "total_weight")
    @Getter @Setter private String totalweight;
}

This is my bean class... Table created to me and it is redirected to next page. 这是我的bean类。表是我创建的,它被重定向到下一页。 but the values we entered in or not inserted in the database. 但是我们输入或未插入数据库的值。

** **

  • MyController class MyController类

** package com.focus.controller; **包com.focus.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.focus.beans.PurchaseDetailsList;
import com.focus.dao.Dao;

public class PurchaseDetail extends HttpServlet {
    private static final long serialVersionUID = 1L;

    PrintWriter out = null;
    boolean flag;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        Dao dao = Dao.getInstance();

        PurchaseDetailsList pdl = new PurchaseDetailsList();

        pdl.setType(request.getParameter("types"));
        pdl.setDate(request.getParameter("date"));
        pdl.setTotalquantity(request.getParameter("totalquantity"));
        pdl.setTotalweight(request.getParameter("totalweight"));
        //System.out.println("Am arun");

        flag =  dao.persist(pdl);
            response.getWriter();
            response.sendRedirect("JSP/PurchaseDetailsListForm.jsp");
    }
}

given values are not inserted into the table. 给定值不会插入表中。 It through an exception "org.hibernate.exception.GenericJDBCException: could not insert:" Please Help me... Am waiting for your answer... 它通过异常“ org.hibernate.exception.GenericJDBCException:无法插入:”请帮助我...正在等待您的答案...

If you look at the hibernate query generated 如果您查看生成的休眠查询

Hibernate: insert into purchase_details (date, total_quantity, total_weight, type) values (?, ?, ?, ?)

primary key is not getting populated correctly, you have used @GeneratedValue for mapping your primary key without any strategy . primary key未正确填充,您已使用@GeneratedValue映射primary key而没有任何strategy So by default Hibernate uses strategy AUTO . 因此,默认情况下, Hibernate使用策略AUTO

From Hibernate docs 来自Hibernate文档

AUTO - either identity column, sequence or table depending on the underlying DB

So hibernate selects the strategy based on the database you use. 因此, hibernate根据您使用的数据库选择策略。

May be try using sequence generator 可以尝试使用sequence generator

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="purchase_seq")
@SequenceGenerator(name="purchase_seq", sequenceName="PURCHASE_SEQ")
private String type_id;

where PURCHASE_SEQ is the name of the sequence you should create database. 其中PURCHASE_SEQ是您应该创建数据库的序列的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.hibernate.exception.GenericJDBCException - org.hibernate.exception.GenericJDBCException org.hibernate.exception.GenericJDBCException:无法在hibernate中执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement in hibernate ested异常是org.hibernate.exception.GenericJDBCException:无法执行查询 - ested exception is org.hibernate.exception.GenericJDBCException: could not execute query org.hibernate.exception.GenericJDBCException:无法执行查询]的根本原因 - org.hibernate.exception.GenericJDBCException: could not execute query] with root cause 如何解决==> org.hibernate.exception.GenericJDBCException:无法打开连接 - how to resolve ==> org.hibernate.exception.GenericJDBCException: Could not open connection org.hibernate.exception.GenericJDBCException:无法执行语句 - org.hibernate.exception.GenericJDBCException: could not execute statement org.hibernate.exception.GenericJDBCException:无法执行查询 - org.hibernate.exception.GenericJDBCException: could not execute query 错误:org.hibernate.exception.GenericJDBCException:无法提取ResultSet - Error: org.hibernate.exception.GenericJDBCException: could not extract ResultSet org.hibernate.exception.GenericJDBCException:无法提取ResultSet - org.hibernate.exception.GenericJDBCException: could not extract ResultSet org.hibernate.exception.GenericJDBCException:无法执行查询 - org.hibernate.exception.GenericJDBCException: could not execute query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM