Insert row to table with the only identifier column with EclipseLink

删除回忆录丶 提交于 2019-12-23 02:56:17

问题


I have an entity:

@Entity
public class MyEntity {

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

    // getter & setter
}

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?

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


回答1:


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).



来源:https://stackoverflow.com/questions/17272819/insert-row-to-table-with-the-only-identifier-column-with-eclipselink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!