我有 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
}
但是当我放置设备并且设置数据具有相同的deviceId并使用repository.findOne(deviceId)查询DeviceSetting时,我没有获取设备数据;
我还需要做什么才能获取设备数据?任何意见将是有益的。谢谢。