gpt4 book ai didi

java - 使用 EclipseLink 将行插入到具有唯一标识符列的表中

转载 作者:行者123 更新时间:2023-11-29 05:28:33 30 4
gpt4 key购买 nike

我有一个实体:

@Entity
public class MyEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = Columns.ID)
private Long id;

// getter & setter
}

然后,我创建了实体 MyEntity my = new MyEntity(); 的一个实例,并想用 DAO 保存它(使用 Spring Data for JPA)- dao.save(my );。我得到以下异常:

Caused by: Exception [EclipseLink-6023] 
(Eclipse Persistence Services - 2.4.0.v20120608-r11652):
org.eclipse.persistence.exceptions.QueryException
Exception Description: The list of fields to insert into the table
[DatabaseTable(my_entity)] is empty.
You must define at least one mapping for this table.
Query: InsertObjectQuery(null)

当我向具有默认值的实体添加另一个无用的列时

private int nothing = 6;

异常消失。有什么解决办法吗?

This topic对我没有帮助。我使用 EclipseLink + MySQL + Spring Data。

最佳答案

这是因为您没有字段,并且使用的是生成的 ID,因此没有可插入的内容。您要么需要添加另一个字段,要么需要使用 TABLE id 生成而不是 IDENTITY(我建议永远不要使用 IDENTITY,因为它不支持预分配)。

关于java - 使用 EclipseLink 将行插入到具有唯一标识符列的表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17272819/

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