对不起我的英语
我在 EclipseLink JPA 中映射实体时遇到一些问题。 我有一些实体:
@Entity
@Table(name = "TSENSOR")
@Cacheable
public class Sensor extends Model implements Serializable {
@EmbeddedId
SensorIdentifier key;
@Column(name = "CDESCRIPTION", columnDefinition = "TEXT")
String description;
@Column(name = "CTYPE")
@Enumerated(EnumType.STRING)
SensorType type;
...
}
@Embeddable
public class SensorIdentifier extends DeviceIdentifier {
@Column(name = "PNUM")
byte num;
...
}
@Embeddable
@MappedSuperclass
public class DeviceIdentifier extends Model implements Serializable {
@Column(name = "PSYSTEM", insertable = false, updatable = false)
String systemName;
@Column(name="PDEVICEID")
int id;
@Column(name="PDEVICESUBID")
short subId;
...
}
在服务器端,该实体映射到 Hibernate JPA 中并且工作得很好。但在客户端上,我需要在 EclipseLink JPA 中映射这个实体(我使用 Eclipse RCP 4.x 和 Gemini DI),但我遇到了这个异常(exception):
Exception [EclipseLink-46] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException Exception Description: There should be one non-read-only mapping defined for the primary key field [TSENSOR.PSYSTEM]. Descriptor: RelationalDescriptor(watchdog.core.client.model.Sensor --> [DatabaseTable(TSENSOR)])
此问题仅适用于包含 EmbeddedId 的实体
最佳答案
该错误表明您应该有一个映射
@Column(name = "PSYSTEM", insertable = false, updatable = false)
String systemName;
可以写入。 (非只读) 因此 PSYSTEM 的另一种映射为 true,可插入或可更新。
关于java - JPA 实体从 Hibernate 到 EclipseLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852309/