使用EclipseLink将行插入到具有唯一标识符列的表中 [英] Insert row to table with the only identifier column with EclipseLink

查看:84
本文介绍了使用EclipseLink将行插入到具有唯一标识符列的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体:

@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);.我遇到以下异常:

Then, I create an instance of the entity MyEntity my = new MyEntity(); and want to save it with DAO (using Spring Data for JPA) - dao.save(my);. I got the following exception:

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)

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

When I add another, useless column to the entity with a default value

private int nothing = 6;

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

Exception disappears. Any solution for that?

本主题对我没有帮助.我使用EclipseLink + MySQL + Spring Data.

This topic does not help me. I use EclipseLink + MySQL + Spring Data.

推荐答案

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

This is because you have no fields, and are using a generated id, so there is nothing to insert. You either need to add another field, or need to use TABLE id generation instead of IDENTITY (I recommend never using IDENTITY as it does not support pre-allocation).

这篇关于使用EclipseLink将行插入到具有唯一标识符列的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆