0
I have a table structure like that :- 

    @Entity
@Table(name = "Load_Container_Tray")
public class LoadContainerTray {

    @EmbeddedId
    private LoadContainerTrayPK loadContainerTrayPK;

    @MapsId("loadContainerPK")
    @JoinColumns({
        @JoinColumn(name = "dest_ebu_nbr", referencedColumnName = "dest_ebu_nbr"),
        @JoinColumn(name = "outbound_load_id", referencedColumnName = "outbound_load_id"),
        @JoinColumn(name = "dest_ebu_cntry_code", referencedColumnName = "dest_ebu_cntry_code"),
        @JoinColumn(name = "ctnr_trackg_id", referencedColumnName = "ctnr_trackg_id") })
    @ManyToOne
    private LoadContainer loadcontainer;
}

@Embeddable public class LoadContainerTrayPK implements Serializable {

private static final long serialVersionUID = 3392075534159950245L;

@Basic
private LoadContainerPK loadContainerPK;

@Column(name = "load_unit_id", columnDefinition = "char(32)")
private String loadUnitId;

}

@Entity
@Table(name = "load_container")
public class LoadContainer {

    @EmbeddedId
    private LoadContainerPK loadContainerPK;

    @MapsId("loadDestinationPK")
    @JoinColumns({
        @JoinColumn(name = "dest_ebu_nbr", referencedColumnName = "dest_ebu_nbr"),
        @JoinColumn(name = "outbound_load_id", referencedColumnName = "outbound_load_id"),
        @JoinColumn(name = "dest_ebu_cntry_code", referencedColumnName = "dest_ebu_cntry_code") })
    @ManyToOne
    private LoadDestination loadDestination;

    @Column(name = "row_nbr")
    private short rowNumber;
}

@Embeddable
public class LoadContainerPK implements Serializable {

    private static final long serialVersionUID = 3392075534159950245L;

    @Basic
    private LoadDestinationPK loadDestinationPK;

    @Column(name = "ctnr_trackg_id")
    private String containerTrackingId;
}

public class LoadDestination {

@EmbeddedId
    private LoadDestinationPK loadDestinationPK;

    @MapsId("outboundLoadId")
    @JoinColumn(name = "outbound_load_id", referencedColumnName = "outbound_load_id")
    @ManyToOne
    private OutboundLoad outboundLoad;

}

@Embeddable
public class LoadDestinationPK implements Serializable {

    private static final long serialVersionUID = -3548089581858405303L;

    @Column(name = "outbound_load_id")
    private String outboundLoadId;

    @Column(name = "dest_ebu_nbr")
    private Integer destinationId;

    @Column(name = "dest_ebu_cntry_code")
    private String destEbuCntryCode;

}
@Entity
@Table(name = "outbound_load")
public class OutboundLoad {

    @Id
    @Column(name = "outbound_load_id", columnDefinition = "char(30)")
    private String outboundLoadId;

    @Column(name = "load_id")
    private int loadId;
}

When i am trying to deploy application on TOMEE server, i am getting this error :-

" org.apache.openejb.OpenEJBException: org.apache.openejb.OpenEJBRuntimeException: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: com.walmart.move.nim.outdoc.entity.LoadContainer: org.hibernate.AssertionFailure: Unexpected nested component on the referenced entity when mapping a @MapsId: com.walmart.move.nim.outdoc.entity.LoadContainer .

Can someone please help me in resolving the issue.

Neer1009
  • 304
  • 1
  • 5
  • 18

1 Answers1

0

I think you should annotate private LoadDestinationPK loadDestinationPK; in LoadContainerPK with @Embedded instead of @Basic, why are you annotating it with @Basic and how will this class be mapped as a Basic type ?

osama yaccoub
  • 1,884
  • 2
  • 17
  • 47
  • I tried to change from Basic to Embedded. but it is showing me compile time error :- Attribute "loadDestinationPK" has invalid mapping type in this context. – Neer1009 Sep 19 '17 at 09:39
  • which version of JPA are you using ? – osama yaccoub Sep 19 '17 at 10:07
  • we are using hibernate-entitymanager-4.2.19.Final and i am using this org.apache.openejb javaee-api 6.0-6 provided . for all JAVA ee features. – Neer1009 Sep 19 '17 at 10:50
  • try to turn off validation for this in Eclipse under `Window -> Preferences -> Java Persistence -> JPA -> Errors/Warnings -> Attributes -> Cannot resolve attribute name` .. as per https://stackoverflow.com/questions/12106124/eclipse-error-on-mapping-with-embeddedid – osama yaccoub Sep 19 '17 at 10:58
  • also try adding `@Access(AccessType.FIELD)` explicitly on `LoadDestinationPK ` ... Annotating nested embedded class with this explicitly (though it's the default) is sometimes the solution – osama yaccoub Sep 19 '17 at 11:12
  • i tried doing this :- @Embeddable @Access(AccessType.FIELD) public class LoadDestinationPK implements Serializable { along with turning off ) . Still getting the same error while deploying code on tomee . Even i am not able to change from Basic to Emebedded. it throws me same error saying " Attribute "loadDestinationPK" has invalid mapping type in this context" – Neer1009 Sep 19 '17 at 12:04
  • " Attribute "loadDestinationPK" has invalid mapping type in this context" at compile or runtime, and did you try removing eclipse validation while adding `@Embedded` ? – osama yaccoub Sep 19 '17 at 13:21
  • error is at compile time only. yes i removed eclipse validation also – Neer1009 Sep 19 '17 at 14:02