Announcement Announcement Module
Collapse
No announcement yet.
Many to one relationship Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Many to one relationship

    Hi all:

    I have two tables Table1 and Table2. Table1 has a composite primary key (GroupSID and MemberSID). Primary key on Table 2 is MemberSID.

    I have implemented Table1 like below
    Code:
    @Entity
    @IdClass(ftg.eas.ops.ps.dto.Table1PK.class)
    public class Table1{
    	private int relationship;
    	private String groupSid;
    	private String memberSid;
    ...
    
    @Embeddable
    public class Table1PK implements Serializable {	
                 private String groupSid;
    	private String memberSid;
    How do I implement ManyToOne relationship with Table2? The ManyToOne uses part of the composite key in Table1. Any example?

    Thank you

  • #2
    ManyToOne

    I have implemented the relationship as shown here
    Code:
    //table2
    	@OneToMany(mappedBy="MemberSID")
    	private List<Table1> members;
    .....
    
    //table1
       @ManyToOne
        @JoinColumn(name="MemberSID", referencedColumnName="SID")
        private Table2 user;
        .....
    When I run the project I get the following error
    Code:
    Internal Exception: Exception [TOPLINK-7150] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.ValidationException
    Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [ftg.eas.ops.ps.dto.Table1PK] and those of the entity bean class [class ftg.eas.ops.ps.dto.Table1] must correspond and their types must be the same. Also, ensure that you have specified id elements for the corresponding attributes in XML and/or an @Id on the corresponding fields or properties of the entity class.
    Both of the above statment are not true. What am I missing?

    Comment

    Working...
    X