title: Mapping & fetching entities with composite keys using spring data JPA
body: <p>I have Spring MVC and Data JPA. I am trying to do mapping tables I have. The structure is like below:</p>
  
  <pre><code>Device
  --------------
  PK deviceId
     deviceName
  
  
  Setting
  --------------
  PK deviceId
  PK packageName
  PK name
     value
  </code></pre>
  
  <p>And I have classes for those tables:</p>
  
  <pre><code>@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
  }
  </code></pre>
  
  <p>But I did not get device data when I put device and setting data has same deviceId and queried DeviceSetting by using repository.findOne(deviceId);</p>
  
  <p>What else do I need to do to get the device data? Any advice would be helpful. Thanks.</p>