gpt4 book ai didi

java - JPA:表中的重复标识符:尝试更新的字段

转载 作者:太空宇宙 更新时间:2023-11-04 09:16:59 31 4
gpt4 key购买 nike

我正在尝试在 Spring-Boot 应用程序中使用 jpa 执行更新。很奇怪,因为我在控制台上看到正在运行更新,但运行后控制台显示

:路径 [] 上下文中 servlet [dispatcherServlet] 的 Servlet.service() 抛出异常 [请求处理失败;嵌套异常是 org.springframework.orm.jpa.JpaSystemException:表中的重复标识符:

我不明白,我没有看到插入语句。

import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "porta")
public class ProfileEntity {
@Id
@Column(name = "idporta")
private Long id;
@Column(name = "title")
private String name;
@Column(name = "imageURL")
private String image;
@Column(name = "description")
private String description;
@Column(name = "twitterName")
private String twitterName;

}

关于配置:

spring:
jpa:
database-platform: org.hibernate.dialect.MySQL5Dialect
hibernate:
ddl-auto: update
naming:
implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate: {show_sql: true, use_sql_comments: true, format_sql: true}

还可以使用下一个 jpa 库

        <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

日志是:

Hibernate: 
/* update
com.app.sample.entities.ProfileEntity */ update
portfo
set
description=?,
imageURL=?,
title=?,
twitterUse=?
where
idporta=?
2019-11-14 00:59:06.524 ERROR 21032 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Duplicate identifier in table for: [com.app.portafolioweb.entities.ProfileEntity#0]; nested exception is org.hibernate.HibernateException: Duplicate identifier in table for: [com.app.sample..entities.ProfileEntity#0]] with root cause

org.hibernate.HibernateException: Duplicate identifier in table for: [com.app.sample..entities.ProfileEntitys#0]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:2563) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3391) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3265) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3666) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:149) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]
at org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478) ~[hibernate-core-5.4.8.Final.jar:5.4.8.Final]

最佳答案

表上是否有更新同一个表的触发器。在触发 FOR UPDATE 触发器的情况下,任何更新语句都会返回 2 个(或更多)更新行,使检查认为存在重复的标识符。

关于java - JPA:表中的重复标识符:尝试更新的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58849968/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com