我有一个实体:
@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;
异常消失。有什么解决办法吗?
这个话题对我没有帮助。我使用 EclipseLink + MySQL + Spring Data。