I am having a issue with onetomany with composite primary key, and I am trying to solve this for some time with no luck
Parent Class
@Entity @Table(name = "dwf_storagegroupsnapshot") public class DMFStorageGroupSnapshotFact extends SPMFact implements Serializable { @Id private LogicalSnapshotFactPK id; @Column(name="devicecount") private Integer deviceCount;
@Column(name="devicemetacount") private Integer metaCount;
@Column(name="capacity") private Integer capacity; @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER) @JoinColumns({ @JoinColumn(name="arraykey",referencedColumnName="arraykey",nullable=false,insertable=true,updatable=true), @JoinColumn(name="timekey",referencedColumnName="timekey",nullable=false,insertable=true,updatable=true), @JoinColumn(name="logicalkey",referencedColumnName="logicalkey",nullable=false,insertable=true,updatable=true) }) private List<DMFStorageTierSnapshotFact> tierFacts; /** * Description: Ctor */ public DMFStorageGroupSnapshotFact() { }
---> Removed getter and setters }
Child Class -
@Entity @Table(name = "dwf_storagetiersnapshot") @IdClass(TierSnapshotFactPK.class) public class DMFStorageTierSnapshotFact implements Serializable { @Id @Column(name="arraykey",insertable=false,updatable=false) private Long arrayKey; @Id @Column(name="timekey",insertable=false,updatable=false) private Long timeKey; @Id @Column(name="logicalkey",insertable=false,updatable=false) private Long logicalKey; @Id @Column(name="tiernumber") private Integer tierNumber; @Column(name="tiername") private String tierName; @Column(name="target") private Integer target; @Column(name="actual") private Integer actual; @Column(name="tiertype") private String tierType; @ManyToOne @JoinColumns({ @JoinColumn(name="arraykey", insertable=false, updatable=false), @JoinColumn(name="timekey", insertable=false, updatable=false), @JoinColumn(name="logicalkey", insertable=false, updatable=false) }) private DMFStorageGroupSnapshotFact sgSnapshotFact; public DMFStorageTierSnapshotFact() {}
}
1. First issue when I generate query using these classes keys are not mapped correctly in OneToMany relation it comes out some thing like "left outer join dwf_storagetiersnapshot tierfacts5_ on this_.arrayKey=tierfacts5_.arraykey and this_.logicalKey=tierfacts5_.timekey and this_.timeKey=tierfacts5_.logicalkey"
2. Second all the primary key columns from the child table is repeated in the select.
Appreciate any help on this.
Thanks.
|