NutzCN Logo
问答 使用 insertOrUpdate, 我的 pojo 类 只有一个 自增长的 唯一主键,插入的时候, 被喷 ” r u kidding me?! It is impossible! “
发布于 2015天前 作者 hui453694187 2135 次浏览 复制 上一个帖子 下一个帖子
标签:
org.nutz.dao.DaoException: java.lang.RuntimeException: r u kidding me?! It is impossible!

	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.NutDao.fetch(NutDao.java:616)
	at org.nutz.dao.impl.NutDao.insertOrUpdate(NutDao.java:1069)
	at org.nutz.dao.impl.NutDao.insertOrUpdate(NutDao.java:1063)
	at com.liqi.health.commonRefund.TerminalStatisitcsJobTest.testStatis(TerminalStatisitcsJobTest.java:128)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at junit.framework.TestCase.runTest(TestCase.java:176)
	at junit.framework.TestCase.runBare(TestCase.java:141)
	at junit.framework.TestResult$1.protect(TestResult.java:122)
	at junit.framework.TestResult.runProtected(TestResult.java:142)
	at junit.framework.TestResult.run(TestResult.java:125)
	at junit.framework.TestCase.run(TestCase.java:129)
	at junit.framework.TestSuite.runTest(TestSuite.java:252)
	at junit.framework.TestSuite.run(TestSuite.java:247)
	at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

下面这个是我的 pojo 类

import com.liqi.health.cloudhospital.pc.searchprint.bean.PrintTimes;
import org.nutz.dao.entity.annotation.Column;
import org.nutz.dao.entity.annotation.Id;
import org.nutz.dao.entity.annotation.Name;
import org.nutz.dao.entity.annotation.Table;

import java.util.Date;

/**
 * Created by kevin on 2019/4/11.
 *
 * @描述: 终端业务量统计
 */
@Table("t_terminal_statistics")
public class TerminalStatistics {


    @Id
    private Long id;
    /**
     * 统计时间 yyyy-MM-dd 格式的日志字符串
     **/
    @Column("statistics_date")
    private String statisticsDate;
    //自助机id号
    @Column("terminal_id")
    private Integer terminalId;

    @Column("terminal_id")
    private Long dtghTotal;

    @Column
    private Long dtghSiTotal;

    @Column
    private Long yyghTotal;

    @Column
    private Long yyghSiTotal;

    @Column
    private Long dtqhTotal;
    //当天取号医保
    @Column
    private Long dtqhSiTotal;
    //门诊缴费自费
    @Column
    private Long mzjfTotal;
    //门诊缴费医保
    @Column
    private Long mzjfSiTotal;
    //急诊
    @Column
    private Long jzghTotal;
    //急诊医保
    @Column
    private Long jzghSiTotal;



    @Column
    private Long jybgTotal;

    @Column
    private Long fpdyTotal;

    @Column
    private Long mzqdTotal;

    @Column
    private Long ecgTotal;


    @Column
    private Date createAt;
    //更新时间
    @Column("last_update_time")
    private Date lastUpdateTime;

    public TerminalStatistics() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreateAt() {
        return createAt;
    }

    public void setCreateAt(Date createAt) {
        this.createAt = createAt;
    }

    public String getPsamCardId() {
        return psamCardId;
    }

    public void setPsamCardId(String psamCardId) {
        this.psamCardId = psamCardId;
    }

    public Long getDtghTotal() {
        return dtghTotal;
    }

    public void setDtghTotal(Long dtghTotal) {
        this.dtghTotal = dtghTotal;
    }

    public Long getDtghSiTotal() {
        return dtghSiTotal;
    }

    public void setDtghSiTotal(Long dtghSiTotal) {
        this.dtghSiTotal = dtghSiTotal;
    }

    public Long getYyghTotal() {
        return yyghTotal;
    }

    public void setYyghTotal(Long yyghTotal) {
        this.yyghTotal = yyghTotal;
    }

    public Long getYyghSiTotal() {
        return yyghSiTotal;
    }

    public void setYyghSiTotal(Long yyghSiTotal) {
        this.yyghSiTotal = yyghSiTotal;
    }

    public Long getDtqhTotal() {
        return dtqhTotal;
    }

    public void setDtqhTotal(Long dtqhTotal) {
        this.dtqhTotal = dtqhTotal;
    }

    public Long getDtqhSiTotal() {
        return dtqhSiTotal;
    }

    public void setDtqhSiTotal(Long dtqhSiTotal) {
        this.dtqhSiTotal = dtqhSiTotal;
    }

    public Long getMzjfTotal() {
        return mzjfTotal;
    }

    public void setMzjfTotal(Long mzjfTotal) {
        this.mzjfTotal = mzjfTotal;
    }

    public Long getMzjfSiTotal() {
        return mzjfSiTotal;
    }

    public void setMzjfSiTotal(Long mzjfSiTotal) {
        this.mzjfSiTotal = mzjfSiTotal;
    }

    public Long getJzghTotal() {
        return jzghTotal;
    }

    public void setJzghTotal(Long jzghTotal) {
        this.jzghTotal = jzghTotal;
    }

    public Long getJzghSiTotal() {
        return jzghSiTotal;
    }

    public void setJzghSiTotal(Long jzghSiTotal) {
        this.jzghSiTotal = jzghSiTotal;
    }

    public Long getJybgTotal() {
        return jybgTotal;
    }

    public void setJybgTotal(Long jybgTotal) {
        this.jybgTotal = jybgTotal;
    }

    public Long getFpdyTotal() {
        return fpdyTotal;
    }

    public void setFpdyTotal(Long fpdyTotal) {
        this.fpdyTotal = fpdyTotal;
    }

    public Long getMzqdTotal() {
        return mzqdTotal;
    }

    public void setMzqdTotal(Long mzqdTotal) {
        this.mzqdTotal = mzqdTotal;
    }

    public Long getEcgTotal() {
        return ecgTotal;
    }

    public void setEcgTotal(Long ecgTotal) {
        this.ecgTotal = ecgTotal;
    }

    public String getStatisticsDate() {
        return statisticsDate;
    }

    public void setStatisticsDate(String statisticsDate) {
        this.statisticsDate = statisticsDate;
    }



    public Integer getTerminalId() {
        return terminalId;
    }

    public void setTerminalId(Integer terminalId) {
        this.terminalId = terminalId;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getNamePlateId() {
        return namePlateId;
    }

    public void setNamePlateId(String namePlateId) {
        this.namePlateId = namePlateId;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }


}

这种无法使用这个 api 批量插入吗?

4 回复

其中 两个字段做 组合的唯一 的索引

  UNIQUE INDEX `uidx_statis_macid` (`terminal_id`,`statistics_date`),

使用 dao.insertOrUpdate 报错 …

是在不行,我这样 ,效率是不是一样的?

private void myInsertOrUpdate(List<TerminalStatistics> list) {
        
        List<TerminalStatistics> insertList = new ArrayList<>();
        List<TerminalStatistics> updateList = new ArrayList<>();
        for (TerminalStatistics terminalStatistics : list) {
            TerminalStatistics t = dao.fetch(TerminalStatistics.class,
                    Cnd.where("statistics_date", "=", terminalStatistics.getStatisticsDate())
                            .and("terminal_id", "=", terminalStatistics.getTerminalId()));
            if(t == null){
                insertList.add(terminalStatistics);
            }else{
                terminalStatistics.setId(t.getId());
                updateList.add(terminalStatistics);
            }
        }
        dao.fastInsert(insertList);
        dao.update(updateList);
    }

效率一样的

添加回复
请先登陆
回到顶部