java - 当我尝试将多个数据插入子表时出现错误无法执行 JDBC 批量更新

标签 java jquery hibernate spring-mvc jsp

我创建了两个类,父类是Credit,子类是Debit。在贷方类中,有六个字段可用,而在借方实体中,只有两个字段是动态添加的 - 金额和描述与 hibernate 的一对多关系。

当我尝试将数据插入两个表时,会发生此错误:

Could not execute JDBC batch update; SQL [insert into debit (amount, description, did) values (?, ?, ?)]; constraint [cid]; nested exception is org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

package com.rojmat.controller;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.commons.collections.bag.SynchronizedSortedBag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.rojmat.entity.Credit;
import com.rojmat.entity.Debit;
import com.rojmat.entity.User;
import com.rojmat.service.CreditService;
import com.rojmat.service.UserService;
import com.rojmat.validation.UserValidation;

@Controller
@RequestMapping(value="/user")
public class UserController {
    @Autowired
    UserService userService;

    @Autowired
    CreditService creditService;

    @RequestMapping(value="/register", method=RequestMethod.GET)
    public String showForm(ModelMap model)
    {
        model.put("userData", new User());
        return "/";
    }
    @RequestMapping(value="/register", method=RequestMethod.POST)
    public String saveForm(ModelMap model, @ModelAttribute("userData")@Valid User user,BindingResult br,HttpSession session)
    {   
        UserValidation userValidation = new UserValidation();
        userValidation.validate(userValidation, br);    
        if(br.hasErrors()) {
            return "/";
        }else {
            userService.add(user);
            //session.setAttribute("user", user);
            return "redirect:/";
        }
    }

    @RequestMapping(value="/login", method=RequestMethod.POST)
    public String doLogin(ModelMap model,@ModelAttribute(value="userData")User user,HttpSession session)
    {   
        if(userService.loginUser(user.getEmail(), user.getPassword()) != null)  {
            session.setAttribute("email",user.getEmail());
            return "redirect:useraccount";
        }else {
            System.out.println("Invalid Email/Password");
            model.put("failed", "Invalid Email/Password");
            return "redirect:/";
        }   
    }
    @RequestMapping(value="/logout",method=RequestMethod.GET)
    public String logOut(ModelMap model, HttpSession session)
    {
        session.removeAttribute("email");
        return "/";
    }
    @RequestMapping(value="/useraccount",method=RequestMethod.GET)
    public String showUserAccount(@ModelAttribute("command")Credit credit, BindingResult br)
    {
        return "useraccount";
    }
    @RequestMapping(value="/useraccount", method=RequestMethod.POST)
    public String userAccount(@ModelAttribute("command")Credit credit, Debit debit, BindingResult br, HttpSession session)
    {
        try {
            //session.setAttribute("useraccount", credit);
            //session.setAttribute("useraccount", debit);
            System.out.println("Amount= "+debit.getAmount());
            System.out.println("Description= "+debit.getDescription());
            creditService.addCreditDebit(credit);
        }catch(Exception e) {
            e.printStackTrace();
        }
        return "redirect:useraccount";
    }
    @RequestMapping(value="/invoicehome", method=RequestMethod.GET)
    public String invoiceHome(@ModelAttribute("command")User user, BindingResult br) {
        return "invoice";
    }
    @RequestMapping(value="/productshome", method=RequestMethod.GET)
    public String productsHome(@ModelAttribute("command")User user, BindingResult br) {
        return "products";
    }
    @RequestMapping(value="/paymenthome", method=RequestMethod.GET)
    public String paymentHome(@ModelAttribute("command")User user, BindingResult br) {
        return "payment";
    }
    @RequestMapping(value="/userprofilehome", method=RequestMethod.GET)
    public String userProfileHome(@ModelAttribute("command")User user, BindingResult br) {
        return "userprofile";
    }
}

package com.rojmat.entity;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.IndexColumn;
import org.springframework.core.annotation.Order;

@Entity
@Table(name="credit")
public class Credit extends BaseEntity{
    @Id
    @GeneratedValue
    @Column
    private long cid;
    @Column @Order
    private long openingbalance;
    @Column
    private Date date;
    @Column @Order
    private long debittotal;
    @Column @Order
    private long drawertotal;
    @Column @Order
    private long debittotalplusdrawertotal;
    @Column @Order
    private long todaybusiness;

    @OneToMany(cascade={CascadeType.ALL})
    @JoinColumn(name="cid")
    @IndexColumn(name="idx")
    private List<Debit> debit;
    public Credit() {

    }
    public Credit(long cid, long openingbalance, Date date, long debittotal, long drawertotal,
            long debittotalplusdrawertotal, long todaybusiness, List<Debit> debit) {
        super();
        this.cid = cid;
        this.openingbalance = openingbalance;
        this.date = date;
        this.debittotal = debittotal;
        this.drawertotal = drawertotal;
        this.debittotalplusdrawertotal = debittotalplusdrawertotal;
        this.todaybusiness = todaybusiness;
        this.debit = debit;
    }
    public long getCid() {
        return cid;
    }
    public void setCid(long cid) {
        this.cid = cid;
    }
    public long getOpeningbalance() {
        return openingbalance;
    }
    public void setOpeningbalance(long openingbalance) {
        this.openingbalance = openingbalance;
    }   
    public Date getDate() {
        return date;
    }
    public void setDate(Date date) {
        this.date = date;
    }
    public long getDebittotal() {
        return debittotal;
    }
    public void setDebittotal(long debittotal) {
        this.debittotal = debittotal;
    }
    public long getDrawertotal() {
        return drawertotal;
    }
    public void setDrawertotal(long drawertotal) {
        this.drawertotal = drawertotal;
    }
    public long getDebittotalplusdrawertotal() {
        return debittotalplusdrawertotal;
    }
    public void setDebittotalplusdrawertotal(long debittotalplusdrawertotal) {
        this.debittotalplusdrawertotal = debittotalplusdrawertotal;
    }
    public long getTodaybusiness() {
        return todaybusiness;
    }
    public void setTodaybusiness(long todaybusiness) {
        this.todaybusiness = todaybusiness;
    }
    public List<Debit> getDebit() { 
        return debit;
    }   
    public void setDebit(List<Debit> debit) {   
        this.debit = debit;
    }   
}

package com.rojmat.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name="debit")
public class Debit {
    @Id
    @GeneratedValue
    @Column
    private long did;
    @Column
    private long amount;
    @ManyToOne
    @JoinColumn(name="cid", insertable=false, updatable=false, nullable=false)
    private Credit credit;
    @Column
    private String description; 

    public Debit() {

    }
    public Debit(long amount, String description) {
        super();
        this.amount = amount;
        this.description = description;
    }
    public long getDid() {
        return did;
    }
    public void setDid(long did) {
        this.did = did;
    }
    public long getAmount() {
        return amount;
    }
    public void setAmount(long amount) {
        this.amount = amount;
    }
    public Credit getCredit() {
        return credit;
    }
    public void setCredit(Credit credit) {
        this.credit = credit;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
}

package com.rojmat.serviceImpl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.rojmat.dao.CreditDao;
import com.rojmat.entity.Credit;
import com.rojmat.entity.Debit;
import com.rojmat.entity.User;
import com.rojmat.service.CreditService;

@Service
@Transactional
public class CreditServiceImpl implements CreditService {

    @Autowired
    private CreditDao creditDao;
    @Override
    public void addCreditDebit(Credit credit) {
        Debit debit = new Debit();
        User user = new User();
     // Credit Data Set
        credit.setOpeningbalance(credit.getOpeningbalance());
        credit.setDate(credit.getDate());
        credit.setDebittotal(credit.getDebittotal());
        credit.setDrawertotal(credit.getDrawertotal());
        credit.setDebittotalplusdrawertotal(credit.getDebittotalplusdrawertotal());
        credit.setTodaybusiness(credit.getTodaybusiness());
        credit.setCreatedBy(user.getEmail());
        credit.setCreatedDate(new Date());
        credit.setUpdatedBy(user.getEmail());
        credit.setUpdatedDate(new Date());
    //  Debit Data set  
        List<Debit> debList = new ArrayList<Debit>();
        credit.setDebit(debList);
        for(int i=0; i<3; i++) {
            debList.add(new Debit(debit.getAmount(), debit.getDescription()));
        }
        credit.getDebit().addAll(debList);
        System.out.println("Debit List= "+debList);
        credit.setDebit(debList);
        creditDao.addCreditDebit(credit);
    }
    @Override
    public void updateCreditDebit(Credit credit) {
        Credit creditdebit = new Credit();
        User user = new User();
        creditdebit.setDebit(credit.getDebit());
        creditdebit.setOpeningbalance(credit.getOpeningbalance());
        creditdebit.setDate(credit.getDate());
        creditdebit.setDebittotal(credit.getDebittotal());
        creditdebit.setDrawertotal(credit.getDrawertotal());
        creditdebit.setDebittotalplusdrawertotal(credit.getDebittotalplusdrawertotal());
        creditdebit.setTodaybusiness(credit.getTodaybusiness());
        creditdebit.setCreatedBy(user.getEmail());
        creditdebit.setCreatedDate(new Date());
        creditdebit.setUpdatedBy(user.getEmail());
        creditdebit.setUpdatedDate(new Date());
        creditDao.updateCreditDebit(creditdebit);
    }
    @Override
    public void deleteCreditDebit(int cid) {
        creditDao.deleteCreditDebit(cid);
    }
    @Override
    public List<Credit> getAllCreditDebit() {
        return creditDao.getAllCreditDebit();
    }

}

package com.rojmat.daoImpl;
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.rojmat.dao.CreditDao;
import com.rojmat.entity.Credit;

@Repository
public class CreditDaoImpl implements CreditDao{

    @Autowired
    private SessionFactory sessionFactory;
    @Override
    public void addCreditDebit(Credit credit) {

        sessionFactory.getCurrentSession().saveOrUpdate(credit);
        /*Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        try
        {
            session.save(credit);
            tx.commit();
        }
        catch(Exception e)
        {
            session.close();
            tx.rollback();
            e.printStackTrace();
        }*/

    }

    @Override
    public void updateCreditDebit(Credit credit) {
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();
        try
        {
            session.update(credit);
            tx.commit();
            session.close();
        }
        catch(Exception e)
        {
            session.close();
            tx.rollback();
            e.printStackTrace();
        }

    }

    @Override
    public void deleteCreditDebit(int cid) {
        /*Credit credit = (Credit)sessionFactory.getCurrentSession().createQuery("from Credit as c LEFT JOIN FETCH c.debit where c.cid="+cid).uniqueResult();
        List<Debit> debits = credit.getDebit();
        sessionFactory.getCurrentSession().delete(credit);
        debits.forEach((debit) -> {
            sessionFactory.getCurrentSession().delete(debit);
        });*/


    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Credit> getAllCreditDebit() {
        List<Credit> credits = sessionFactory.getCurrentSession().createQuery("from Credit,Debit").list();
        return credits;
    }

}

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Accounting</title>   
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="<c:url value="/resources/css/dashboard.css"/>" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.5/validator.min.js"></script>
</head>
<body> 
<!-- Navigation Bar -->     
<section id="nav-bar">
    <nav class="navbar navbar-expand-lg navbar-light">
    <a class="navbar-brand" href="#"><img alt="" src=""></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ml-auto">
        <li class="nav-item">
            <a class="nav-link" href="${pageContext.request.contextPath}/user/useraccount">Rojmat</a>
        </li>
        <li class="dropdown">
            <a href="#" data-toggle="dropdown" class="dropdown-toggle nav-link">Products <b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li><a href="${pageContext.request.contextPath}/category/addCategory">Category</a></li>
                <li><a href="${pageContext.request.contextPath}/product/addProduct">Product</a></li>
                <li class="divider"></li>
                <li><a href="${pageContext.request.contextPath}/unit/addUnit">Unit</a></li>
                <li><a href="${pageContext.request.contextPath}/gst/addGst">GST</a></li>
            </ul>
        </li>
        <li class="nav-item dropdown">
            <a href="#" data-toggle="dropdown" class="dropdown-toggle nav-link">Payment <b class="caret"></b></a>
            <ul class="dropdown-menu">
                <li><a href="${pageContext.request.contextPath}/paymentt/paytype">Payment Mode</a></li>
                <li class="divider"></li>
                <li><a href="${pageContext.request.contextPath}/sales/addsales">Sales Payment</a></li>
                <li><a href="${pageContext.request.contextPath}/purchase/addpurchasepay">Purchase Payment</a></li>
            </ul>
        </li>
        <li class="nav-item dropdown">
            <a href="#" data-toggle="dropdown" class="dropdown-toggle nav-link">Ledger<b class="caret"></b></a>
            <ul class="dropdown-menu">
               <li><a href="${pageContext.request.contextPath}/cust/addcustomer">Customer</a></li>
                <li><a href="${pageContext.request.contextPath}/supp/addsupplier">Supplier</a></li>
                <li class="divider"></li>
                <li><a href="${pageContext.request.contextPath}/state/addstate">States</a></li>
            </ul>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="${pageContext.request.contextPath}/user/invoicehome">Invoice</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="${pageContext.request.contextPath}/user/userprofilehome">User Profile</a>
        </li>
        <li class="nav-item">
            <a class="nav-link" href="${pageContext.request.contextPath}/">LogOut</a>
        </li>
    </ul>
  </div>
</nav>
</section>      
    <h1>Rojmat (Daily Account)</h1><br/>
    <div class="container">
        <div class="row">
            <form:form action="${pageContext.request.contextPath}/user/useraccount" method="POST" id="myForm" modelAttribute="command">
            <div class="col-md-5">
                <h3>Credit Account</h3>
                <div class="form-group">
                    <form:label path="openingbalance">Opening Balance :</form:label>
                    <form:input path="openingbalance" id="openingBalance" value="${user.openingbalance}" class="form-control" autocomplete="off" placeholder="Opening Balance"/>
                    <small id="openingBalancechk"></small>
                </div>
                <div class="form-group">
                    <form:label path="debittotalplusdrawertotal">Debit Total + Drawer Total :</form:label>
                    <form:input path="debittotalplusdrawertotal" id="debitplusdrawertotal" value="${user.debitplusdrawertotal}" class="form-control" autocomplete="off"/>
                    <small id="debitplusdrawertotalchk"></small>
                </div>
                <div class="form-group">
                    <form:label path="todaybusiness">Today Business :</form:label>
                    <form:input path="todaybusiness" id="todaybusiness" value="${user.todaybusiness}" class="form-control" autocomplete="off"/>
                    <small id="todaybusinesschk"></small>
                </div>
                <%-- <div class="form-group">
                    <form:label path="date">Date :</form:label>
                    <form:input path="date" id="date" value="${user.date}" class="form-control" autocomplete="off"/>
                    <small id="datechk"></small>
                </div> --%>
                <button class="btn btn-primary" id="savebtn">Save</button>
            </div>
            <div class="col-md-6">
            <h3>Debit Account</h3>
            <input type="button" class="btn btn-primary" value="Add Row" id="addRow"/>&nbsp;&nbsp;
            <input type="button" class="btn btn-danger" id="deleteRow" value="Delete"/><br>
                <table class="table table-hover table-bordered" id="tableid">
                    <thead>
                        <tr>
                            <th>Select</th>
                            <th>Amount</th>
                            <th>Description</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody> 
                </table>
                <div class="form-group">
                    <form:label path="debittotal">Debit Total:</form:label>
                    <form:input path="debittotal" id="debittotal" value="${user.debittotal}" class="form-control" autocomplete="off"/>
                    <small id="debittotalchk"></small>
                </div>
                <div class="form-group">
                    <form:label path="drawertotal">Drawer Total :</form:label>
                    <form:input path="drawertotal" id="drawertotal" value="${user.drawertotal}" class="form-control" autocomplete="off"/>
                    <small id="drawertotalchk"></small>
                </div>
            </div>
            </form:form>
        </div>
    </div>
    <script src="<c:url value="/resources/js/dashboard.js"/>"></script>
</body>
</html>
        $(document).ready(function(){
            $("#addRow").click(function(){
                var dc='amount' + parseInt($('[data-val="amount"]').length +1);
                var dcAmount= parseInt($('[data-val="amount"]').length +1);
                var dc1='amountchk' + parseInt($('[data-val="amount"]').length +1);
                var markup = "<c:forEach items='${Debit.debit}' var='debit' varStatus='status'>" + "<tr><td><input type='checkbox' name='record'></td>"+
                        "<td><input type='text' name='amount' id='amount' class='form-control'/>" + "<small id='amountchk' class="+dc1+"></small></td>" +
                        "<td><input type='text' name='description' id='description' class='form-control'/></td></tr>"+"</c:forEach>";
                $("table tbody").append(markup);
            });
            $("#addRow").click(function() {
                $('input[name="amount"]').css({
                    "font-size": "13px",
                    "color": "#777",
                    "border-radius": "20px",
                    "border": "none !important"
                });

                $('input[name="description"]').css({
                    "font-size": "13px",
                    "color": "#777",
                    "border-radius": "20px",
                    "border": "none !important"
                });
            });
            // remove selected table rows
            $("#deleteRow").click(function(){
                $("table tbody").find('input[name="record"]').each(function(){
                    if($(this).is(":checked")){
                        $(this).parents("tr").remove();
                    }
                });
            });
            /*******Debit Total *****************/
            $("#tableid").on('input','#amount',function(){
                var total = 0;
                $("#tableid #amount").each(function() {
                    var get_value = $(this).val();
                    if($.isNumeric(get_value)) {
                        total += parseInt(get_value); 
                    }
                });
                $("#debittotal").val(total);
            });

            /*******Debit Total + Drawer Total *****************/
            $('#debittotal').keyup(function() {
                debitPlusDrawer();
            });
            $('#drawertotal').keyup(function() {
                debitPlusDrawer();
            });
            function debitPlusDrawer() {
                var debit_total = $('#debittotal').val();
                var drawer_total = $('#drawertotal').val();
                var debit_Drawer = parseInt(debit_total) + parseInt(drawer_total);
                if($.isNumeric(debit_Drawer)) {
                    $("#debitplusdrawertotal").val(debit_Drawer);
                }
            }

            /*************** DebitTotalPlus_DrawerTotal - Opening_Balance **********/

            $('#debitplusdrawertotal').keyup(function() {
                Debit_minus_OpeningBalace();
            });$('#openingBalance').keyup(function() {
                Debit_minus_OpeningBalace();
            });

            function Debit_minus_OpeningBalace() {
                var debit_Drawer = $('#debitplusdrawertotal').val();
                var opening_Balance = $('#openingBalance').val();
                var today_Business = parseInt(debit_Drawer) - parseInt(opening_Balance);
                if($.isNumeric(today_Business)) {
                    $("#todaybusiness").val(today_Business);
                }
            }

            $('#openingBalancechk').hide();
            $('#debittotalchk').hide();
            $('#drawertotalchk').hide();
            $('#debitplusdrawertotalchk').hide();
            $('#todaybusinesschk').hide();
           // $('#datechk').hide();
            $('#amountchk').hide();

            var openingBalance_err = true;
            var debittotal_err = true;
            var drawertotal_err = true;
            var debitdrawertotal_err = true;
            var todaybusiness_err = true;
        //    var date_err = true;
            var amount_err = true;

            $('#openingBalance').keyup(function() {
                openingBalance_chk();
            });
            function openingBalance_chk() {
                var openingbalance = $('#openingBalance').val();
                var pattern = /^\d*(?:\.\d{1,2})?$/;
                if((openingbalance.length == '') || (openingbalance.length == null)) {
                    $('#openingBalancechk').show();
                    $('#openingBalancechk').html("Please Fill Opening Balance");
                    $('#openingBalancechk').focus();
                    $('#openingBalancechk').css("color","red");
                    openingBalance_err = false;
                    return false;
                } else {
                    $('#openingBalancechk').hide();
                }
                if(!pattern.test(openingbalance)) {
                    $('#openingBalancechk').show();
                    $('#openingBalancechk').html("Please enter only numbers 0-9");
                    $('#openingBalancechk').focus();
                    $('#openingBalancechk').css("color","red");
                    openingBalance_err = false;
                    return false;
                } else {
                    $('#openingBalancechk').hide();
                }
            }

            $('#debittotal').keyup(function() {
                debittotal_chk();
            });

            function debittotal_chk() {
                var debittotal = $('#debittotal').val();
                var pattern = /^\d*(?:\.\d{1,2})?$/;
                if((debittotal.length == '') || (debittotal.length == null)) {
                    $('#debittotalchk').show();
                    $('#debittotalchk').html("Please Fill Debit Total");
                    $('#debittotalchk').focus();
                    $('#debittotalchk').css("color","red");
                    debittotal_err = false;
                    return false;
                } else {
                    $('#debittotalchk').hide();
                }
                if(!pattern.test(debittotal)) {
                    $('#debittotalchk').show();
                    $('#debittotalchk').html("Please enter only numbers 0-9");
                    $('#debittotalchk').focus();
                    $('#debittotalchk').css("color","red");
                    debittotal_err = false;
                    return false;
                } else {
                    $('#debittotalchk').hide();
                }
            }


        }); 

最佳答案

在你的类(class)借方

在您的类 CreditServiceImpl 函数 addCreditDebit 中,您执行以下操作:

credit.setDebit(debList);
creditDao.addCreditDebit(credit);

因此,您设置属性借方,然后更新或更新您的实体贷方。

但是在你的类借记中有一行:

@JoinColumn(name="cid", insertable=false, updatable=false, nullable=false)
private Credit credit;

尝试删除 insertable=falseupdatable=false

关于java - 当我尝试将多个数据插入子表时出现错误无法执行 JDBC 批量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57164024/

相关文章:

java - Spring 数据 JPA : Batch insert for nested entities

java - 我的 LWJGL 和 Slick2d 应用程序无法从可运行的 jar 文件运行

php - 不错的 url 传递变量

javascript - 为什么 return false 会停止警报?

java - mysql 数据类型 SET 的 Hibernate 注释

hibernate - 在 Hibernate 中防止 SQL 注入(inject)

java - Android NDK反编译 native 代码的可能性

javascript - 如何在容器中放置旋转图像?

hibernate - 如果我可以配置 hibernate.cfg.xml (Hibernate),我应该如何配置 (JPA) 我的 persistence.xml 文件?

java - 使用 Exchange Web 服务 Java API 下载附件?