Issue
I have a class FsetConsolidatedHoldings and its primary key put in FsetConsolidatedHoldingsPK. Similarly, I have the classes HolderType and HolderTypePK. I want to use variables in the HolderType class in a query including the inner join of FsetConsolidatedHoldings and HolderType
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "fset_consolidated_holdings", schema = "mket_data")
public class FsetConsolidatedHoldings extends HolderType{
private static final long serialVersionUID = 1LL;
@EmbeddedId
private FsetConsolidatedHoldingsPK id;
@Column(name = "end_date")
private LocalDate endDate;
@Column(name = "fset_proper_name")
private String fProperName;
This is the FSetConsolidatedHoldingsPK class
import java.io.Serializable;
import java.time.LocalDate;
import javax.persistence.Column;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class FsetConsolidatedHoldingsPK implements Serializable{
private static final long serialVersionUID = 1LL;
@NotNull
@Column(name = "fsym_id")
private String fsymId;
This is the HolderType class
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "holder_type", schema = "mket_data")
@Inheritance
public class HolderType {
@EmbeddedId
private HolderTypePK holderTypeCode;
@Column(name = "holder_type_description")
private LocalDate holderTypeDescription;
@Column(name = "created_by")
private String createdBy;
This is the HolderTypePK class
import java.io.Serializable;
import java.time.LocalDate;
import javax.persistence.Column;
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class HolderTypePK implements Serializable {
@NotNull
@Column(name = "holder_type_code")
private String holderTypeCode;
}
I am getting the following error. org.hibernate.AnnotationException:
com.ds.ind.hibernateEntities.FsetConsolidatedHoldingsPK must not have @Id properties when used as an @EmbeddedId: com.ds.ind.hibernateEntities.FsetConsolidatedHoldings.id
Solution
I think you just need to annotate FsetConsolidatedHoldingsPK
and HolderTypePK
with @Embeddable
Answered By - Christian Beikov
Answer Checked By - Marie Seifert (JavaFixing Admin)