简体   繁体   中英

JPA Entity from Hibernate to EclipseLink

Sorry for my English

I have some problems with mapping entity in EclipseLink JPA. I have some entity:

@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;

    ...

}

On server-side this entity mapped in Hibernate JPA and work excelent. But on client i need mapped this entity in EclipseLink JPA (I work with Eclipse RCP 4.x and Gemini DI), and i had this 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)])

This problem only with entity contains EmbeddedId

The error says that you should have one mapping for

@Column(name = "PSYSTEM", insertable = false, updatable = false)
String systemName;

that can be written to. (non-read-only) So one other mapping for PSYSTEM with insertable or updatable on true.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM