我需要在已嵌入主键的实体上编写批量插入查询
我有以下实体,
@Entity
@Table(name = "MAP_SCHEDULE_LOB")
public class MapScheduleLob implements java.io.Serializable {
private MapScheduleLobId id;
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "scheduleReferenceId", column = @Column(name = "SCHEDULE_REFERENCE_ID", nullable = false, precision = 38, scale = 0)),
@AttributeOverride(name = "lobCode", column = @Column(name = "LOB_CODE", nullable = false, length = 30)),
@AttributeOverride(name = "sapThreadStatus", column = @Column(name = "SAP_THREAD_STATUS", nullable = false))
})
public MapScheduleLobId getId() {
return this.id;
}
public void setId(MapScheduleLobId id) {
this.id = id;
}
}
以下是我的嵌入式实体,
@Embeddable
public class MapScheduleLobId implements java.io.Serializable{
private Long scheduleReferenceId;
private String lobCode;//default
public MapScheduleLobId(Long scheduleReferenceId, String lobCode) {
this.scheduleReferenceId = scheduleReferenceId;
this.setLobCode(lobCode);
this.setSapThreadStatus(0);
}
@Column(name = "SCHEDULE_REFERENCE_ID", nullable = false, precision = 38, scale = 0)
public Long getScheduleReferenceId() {
return this.scheduleReferenceId;
}
public void setScheduleReferenceId(Long scheduleReferenceId) {
this.scheduleReferenceId = scheduleReferenceId;
}
@Column(name="LOB_CODE",nullable=false,length = 30)
public String getLobCode() {
return lobCode;
}
public void setLobCode(String lobCode) {
this.lobCode = lobCode;
}
}
现在我已经执行了JPQL查询,如
插入MapScheduleLob(scheduleReferenceId,lobCode)从DownloadScheduleView模型中选择新的com.eks.srs.service.schedule.entity.MapScheduleLobId(model.id.scheduleReferenceId,model.lobCode),其中model.id.scheduleReferenceId = 10
它给了我例外。如果我没有嵌入式密钥,则上述查询有效。
所以任何人都可以帮助如何使用Embedded Key编写批量插入查询。
我使用过EJB 3.1和JPA,Hibernate 4和Jboss 7.2。