JPA实体没有主键? [英] JPA entity has no primary key?
本文介绍了JPA实体没有主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Entity类:
@Entity
@Table(name =CMC_MAP_SERVER_INFO)
@NamedQuery(name =CmcMapServerInfo.getMapServer,query =SELECT c FROM CmcMapServerInfo c)
public class CmcMapServerInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name =APPLICATION_NAME)
private String applicationName;
private String remarks;
@Column(name =SERVER_IP)
private String serverIp;
@Column(name =SERVER_NAME)
private String serverName;
@Column(name =SERVER_PORT)
private short serverPort;
public CmcMapServerInfo(){
}
以下错误:
实体类[class cdot.oss.cmsat.conf.ejb.entity.CmcMapServerInfo]没有指定主键。
我在线阅读,发现实体必须定义主键。
但是这里的表只有一个行表。它只是用来保存系统配置。
所以只有查询我想做的是检查行是否存在,然后获取该行并更新它。 >
我的列是 serverIp,端口,服务器名称。
要移除此错误?
解决方案
- 实体类必须用
Entity
注释注释。 - 实体类必须有一个无参构造函数。 / li>
- 实体类不能是最终实体
- 实体类必须实现
Serializable
li>
- 实体类必须具有唯一的不可变的
ID
$ b b
否则,你不能。
I have an Entity class:
@Entity
@Table(name="CMC_MAP_SERVER_INFO")
@NamedQuery(name="CmcMapServerInfo.getMapServer", query="SELECT c FROM CmcMapServerInfo c")
public class CmcMapServerInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="APPLICATION_NAME")
private String applicationName;
private String remarks;
@Column(name="SERVER_IP")
private String serverIp;
@Column(name="SERVER_NAME")
private String serverName;
@Column(name="SERVER_PORT")
private short serverPort;
public CmcMapServerInfo() {
}
I get the following error:
Entity class [class cdot.oss.cmsat.conf.ejb.entity.CmcMapServerInfo] has no primary key specified.
I read online and found out that entities must have a primary key defined. But my table here is a ONE row table only. It just used to save system configuration.
So only queries I will like to do will be to check if the row exists then get that row and update it.
My columns are serverIp, port, name of the server.
How should I proceed to remove this error?
解决方案
- Entity class must be annotated with the
Entity
annotation. - Entity class must have a no-arg constructor.
- Entity class must not be final
- Entity class must implement the
Serializable
interfaces. - Entity class must have a unique, immutable
ID
Otherwise, you cannot.
这篇关于JPA实体没有主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文