Announcement Announcement Module
No announcement yet.
Many to one relationship Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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
    public class Table1{
    	private int relationship;
    	private String groupSid;
    	private String memberSid;
    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

    I have implemented the relationship as shown here
    	private List<Table1> members;
        @JoinColumn(name="MemberSID", referencedColumnName="SID")
        private Table2 user;
    When I run the project I get the following error
    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 [] and those of the entity bean class [class] 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?