Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测绘及;使用spring数据JPA获取具有复合键的实体_Jpa_Spring Data Jpa - Fatal编程技术网

测绘及;使用spring数据JPA获取具有复合键的实体

测绘及;使用spring数据JPA获取具有复合键的实体,jpa,spring-data-jpa,Jpa,Spring Data Jpa,我有Spring MVC和Data JPA。我正在尝试映射我拥有的表。结构如下: Device -------------- PK deviceId deviceName Setting -------------- PK deviceId PK packageName PK name value 我为这些表格上了课: @Entity public class DeviceSetting implements Serializable { @EmbeddedId

我有Spring MVC和Data JPA。我正在尝试映射我拥有的表。结构如下:

Device
--------------
PK deviceId
   deviceName


Setting
--------------
PK deviceId
PK packageName
PK name
   value
我为这些表格上了课:

@Entity
public class DeviceSetting implements Serializable {
    @EmbeddedId
    private String deviceId
    private String deviceName;

    @ManyToOne
    @JoinColumn(name="deviceId", referencedColumnName="deviceId", insertable=false, updatable=false)
    private Device device;

    //Setters and Getters
}

@Embeddable
public class DeviceSettingPk implements Serializable {

    private String deviceId;
    private String packageName;
    private String name;

    public DeviceSettingPk(){}
    public DeviceSettingPk(String deviceId, String packageName, String name) {
        super();
        this.deviceId = deviceId;
        this.packageName = packageName;
        this.name = name;
    }

       //Setters and Getters
}

@Entity
public class Device implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotEmpty
    @Id
    @Column(name="deviceId")
    private String deviceId;

        private String deviceName;

        //Getters and Setters
}
但当我使用repository.findOne(deviceId)将设备和设置数据放在具有相同deviceId的位置并查询DeviceSetting时,并没有获取设备数据


我还需要做什么来获取设备数据?任何建议都会有帮助。谢谢。

如下更改映射

@Entity
public class DeviceSetting implements Serializable {
    @EmbeddedId
    private DeviceSettingPk deviceSettingId;


    @ManyToOne
    @JoinColumn(name="deviceId", referencedColumnName="deviceId", insertable=false, updatable=false)
    private Device device;

    //Setters and Getters
}
然后使用以下代码进行查找

DeviceSettingPk id = new DeviceSettingPk(deviceId, packageName, name);

// use the deviceSettingRespository to lookup
repository.findOne(id);