How to represent an association "many to many" with an association class?

I work with JPA (and TopLink essentials).
Class Person
Class Project
Association M:N between these 2 classes. A person has a function in each project she participates in.
My relational schema:
table PERSON, primary key person_id, person_name,...
table PROJECT, primary key project_id, project_name,...
table PARTICIPATION,
- primary key (person_id, project_id). person_id references PERSON and project_id references PROJECT.
- column "function".
How to write the entities Person, Project and Participation so that they map the relational schema? I don't know what to put as the "id" (@Id) of the class Participation
I know how to solve the problem by adding an attribute id (annotated by @Id) in the class Participation that would map to an id column in the table PARTICIPATION but I would like to match exactly the relational schema: the primary key of PARTICIPATION is (person_id, project_id) and not another id column.
Thanks in advance for your answers.

Thanks for your answer. I see what I have to do.
There are 2 items I don't understand in your message. My questions are beneath, inside the text of your message:
You have a m-m relationship with additional
information in the join table. To map this you need
an object representing the join table, in your case
you have chosen Participation. So you basically need
to define a 1-m from Person to Participation and a
1-m from Project to Participation (unless you only
care about access from one side).
Participation should have a 1-1 to Person and another
1-1 to Project using the two foreign key fields.I would say they are m-1 associations. But perhaps you have made a typing error?
Although TopLink allows 1-1 mappings to be used a
primary keys, the JPA Spec requires that you have
basic mappings, so you also need a personId and
projectId attribute in the Participation.I don't understand. Can you detail your answer?
I have not found the section of the JPA specification which says how to do with 2 mappings.
>
Because you will have two mappings for the same
foreign key field, in TopLink you will require to set
one of them read-only, you do this in JPA through
setting insertable and updateable on the @Column to
false.

Similar Messages

  • How to represent java generics in UML

    Hello,
    Can anyone tell me how to represent java generics in UML? Say I have ClassA<ClassB>. How do I represent this in UML?
    Thanks in advance,
    Julien Martin.

    More formally you can use parameterized types.
                : T:Classifier :
      +---------:..............:
      |    ClassA    |
    <<bind>> <T -> ClassB>
    | ClassA<ClassB> |
      Which may be useful if you have different instantiations of ClassA<T> with different values of T.
    Pete
    (I really must get round to making an ascii art UML editor sometime)

  • How to replicate a many to many schema

    Hi,
    We are trying to replicate a many to many schema as the following:
    Table: STATE
    Name ¿Null? Type
    ID_STATE NOT NULL NUMBER
    STATE_NAME NOT NULL VARCHAR2(32)
    Table: USER
    Name ¿Null? Type
    ID_USER NOT NULL NUMBER
    USER_NAME NOT NULL VARCHAR2(32)
    Table: USER_STATE
    Name ¿Null? Type
    ID_USER NOT NULL NUMBER
    ID_STATE NOT NULL NUMBER
    We have a configuration with three nodes, one master node and two slave nodes in each state.
    We would like to have a subsetting configuration, where only the Users that belong to the State 1, are replicated to first node, and the Users that belong to the State 2, are replicated to the second node.
    Is possible to make this configuration using subsetting rules? We have tried to do that but as subsetting has to be configured only for each table, is not possible to make it work with the three tables working together. For example, if I insert one record in the table USER, it must not be replicated, as it is no associated with any state... after if I insert a record in the table USER_STATE, for this user, making him belong to the state one, it must replicate this record but ALSO the record in the table USER that now belongs to the state 1...
    Is possible to get this working? And if it is, how?
    Thank you all.

    It may be possible to do this using a 1-many custom rule-based transformationon the capture rules.
    <p>
    With a 1-many transformation on a rule, a single LCR is passed into your PL/SQL function as an array of size 1. On return from the function, your procedure will return an array of anydata with 2 LCRs (the original LCR and a newly created LCR ).
    <p> For example: for a change(LCR) that occurs in the USER_STATE table, you can construct an additional LCR for the USER table and return both LCRs to the capture process. You may need to add an additional column (add_column) to associate this new USER LCR with the state. This would be temporary so that this user record can go along the same path as the user_state record. At the destination, you would eliminate the extra STATE column with a delete_column call with an apply rule declarative transformation..
    <p>
    Another variation: if there are only 2 states, you could have a separate capture for each state and just do the 1-many transformation on each capture. In this case, it would not be necessary to add an temporary state column to the LCR.
    Both of these solutions will have an impact on performance, as a PL/SQL function is called every time the rule that includes the custom transformation evaluates to TRUE.

  • Cascade delete in many to many association

    Hi All,
        I have a usecase, there is an association with many to many cardinality  between 3 EO's. If i delete  any record in master, the corresponding childs all should delete.
        So appreciate if any alternatives on above usecase. Thanks in advance

    Hi,
    cascade delete is a function of the database. When you enable cascade delete for an entity operation then this only produces the proper SQL code for deleting a data object. If you have a many-to-many relation then this means you have multiple master and child records, which I think makes your "If i delete  any record in master, the corresponding childs all should delete" impossible.
    for what its worth, please read
    Creating a Business Domain Layer Using Entity Objects - 11g Release 2 (11.1.2.3.0)
    to learn how to parse and delete detail records  from an entity object
    http://docs.oracle.com/cd/E35521_01/web.111230/e16182/bcentities.htm#CEGJAFCF
    The last document is about posting orders (e.g. create a master record before you create detail records). However, with a few changes you can reverse this to perform a delete operation (just add this code to the entity impl classes of the entities so they delete their child objects
    Frank

  • How to handle Many-to-Many tables

    I have table_1 with a primary key, x
    I have table_2 with primary key y
    Table_3 represents the many-to-many relationship between table_1 and table_2, and has a primary key x,y.
    Okay - so I know how to set up master detail forms for table_1 and for table_2, but what type of form do I use for table_3? I want to use the primary key of table_1 as an item (:pagenum_x, I guess) and then select from a drop-down list for key y.
    I am am newbie, so if this is somewhere in the documentation (I can't find it after a few days trying), just tell me to keep looking. :)
    Norm

    Vojin,
    Thanks for the reply. It helps to have some corroboration when these types of issues come up.
    I can create regions or pages that handle the associations, but it seems as though I am fighting or fooling the product (APEX) to do so. Maybe adding the rowid with a sequence / trigger will simplify the design.
    Thanks,
    Norm

  • Delete entity that participate in many to many association

    Hi all,
    I have two tables related by a many to many relationship (for ex department and employee).
    So I have three tables:
    Department: table of departments
    Employee: table employees
    deptEmp: the association table relating the employees to the departments.
    When a department is deleted, all the corresponding rows in deptEmp table should also be deleted (and same for employee).
    On the entity level, I have created the many to many association (between department and employee) and a one to many association for each of department and employee entities to deptEmp entity (deptEmptAssoc from department to deptEmp and empDeptAssoc employee  to deptEmp).
    I configured the deptEmptAssoc association to be a composition and implement the cascading delete, and it is working fine. When I delete a department, the corresponding rows in deptEmp are deleted.
    The problem is that when I try to do the same for empDeptAssoc, JDev gives me a warning and doesn’t apply the composition neither the cascading delete.
    I tried to override the remove method of employee entity to also remove the corresponding deptEmp but it also didn’t work.
    So any hint or pointer how to achieve this? How to have a many to many association and be able to delete both sides of the association?
    Thank you.

    Hi,
    This behavior can be done by overriding the postChanges method as follow:
      public void postChanges(TransactionEvent transactionEvent) {
            if(getPostState() == STATUS_DELETED){
                RowIterator mmIterator = getMM();
                while (mmIterator.hasNext()){
                    EntityImpl row = (EntityImpl)mmIterator.next();
                    row.remove();
    row.postChanges(transactionEvent);
            super.postChanges(transactionEvent);
    N.B.1  In the xml file of the viewLink, the composition association (and implement cascade delete) should not be checked.
    N.B.2  with these flags unchecked, ADF will not control the posting of entities in case the department and the deptEmp entities were both newly created. To fix the issue, the deptEmp entity should also override the postChanges method as follow:
                        public void postChanges(TransactionEvent transactionEvent) {
            if (getPostState() == STATUS_NEW ||
                  getPostState() == STATUS_MODIFIED) {
                EntityImpl dept = getDept();
                if (dept != null) {
                  if (dept.getPostState() == STATUS_NEW) {
    dept.postChanges(transactionEvent);
                                                    // do the same for the Employee entity if needed
            super.postChanges(transactionEvent);
    Regards.

  • Representing many-to-many relationships

    The data structure I am working with is a many-to-many relationship between clients and contacts, managed by a client_contact intersection table
    I have been rather unsuccessfully trying to use the JHeadstart generator to generate a master-detail style relationship between clients and contacts. The new intersection shuttle is great for being able to be maintain the intersection table and have that working fine but I would also like to set up a master-detail group
    I have created a ContactsForClient view that combines the Contacts and Client_contacts entities with a bind parameter of client id and created a view link between clients VO and the ContactsForClient VO. Setting this up in the JHeadstart generator works fine for displaying and modifying the associated contacts - but adding new contacts is where the problem lies. The ContactsForClient group uses a table structure with empty rows at the bottom for inserting new contacts. I am unsure of how to be able to manage the client_contact instersection table in behind the scenes. The ClientContactsImpl fires first - at which stage I only have client id and not the contact id. I want to be able to force the ContactsImpl to run first and retrieve the DB Sequence that was used to populate the contact id on the contacts table, using that to populate the client-contacts table.
    I saw some code to force a new dept to be posted before the emp record and thought I could utilise that but it does not work
      public void postChanges(TransactionEvent e) {
        System.out.println("In postChanges");
        if (getPostState() == STATUS_NEW)
          System.out.println("Status is new");
          ContactsImpl newContact = getContacts();
          if (newContact != null) {
            System.out.println("newContact not null");
            if (newContact.getPostState() == STATUS_NEW) {
              newContact.postChanges(e);
              // retrieve DB sequence used to populate contacts ct_id
              // and use to set clientcontacts ct_id
              System.out.println("newContact changes posted");
        super.postChanges(e);
      }newContact is always null ! I realise I could create separate screens to create the contacts and then the intersection-shuttle to assign them to a client but is there anyway I can do this in a way that mimics normal master-detail JHeadstart functionality ?
    Any help would be greatly appreciated !

    Managed to get my problem solved - I was over-complicating things ! I did however run into the reason (after a substantial process of elimination) why the postchanges method was not working as expected.
      public void postChanges(TransactionEvent e) {
        if ((getPostState() == STATUS_NEW) || (getPostState() == STATUS_MODIFIED)) {
          EntityImpl gio = getGoodsInOut();
          if (gio != null) {
            if (gio.getPostState() == STATUS_NEW) {
              gio.postChanges(e);
        super.postChanges(e);
      }My master EO is GoodsInOut and my detail EO is product. When I was running this code from the ProductsImpl, the getGoodsInOut() was always returning a null value and therefore I was unable to force the posting of the master before the detail. The problem turned out to be a "before insert for each row" trigger on the GoodsInOut table. This trigger was just setting the sequence but for some reason, after firing, causes the relationship between the GoodsInOut master and the Products detail to be lost, with getGoodsInOut() returning null. As soon as I dropped the database trigger and set the sequence in the EO's create method - it worked fine. I realise this is a "JDeveloper" question rather than a "JHeadstart" question so I will post this on the JDeveloper forum as well but thought you may have some ideas on why the database trigger is causing that behaviour and also how I can still retrieve the GoodsInOut EntityImpl with a database trigger (want this for auditing purposes) - perhaps make the call to getGoodsInOut at an earlier stage in the processing (ie before the database trigger runs) ?
    Cheers,
    Brent Harlow

  • New User Question : Many to Many relationship Association

    Hi
    I am trying to code a many to many relationship between two entities. One of my entity is named View and the other is Column.
    I am trying to use the @JoinTable annotation and for the table property in the annotation I am specifying a table column_view (which I have created in the database).
    My associative table has other fields, apart from the primary key of view and column entities. This makes me feel that my current way of using @JoinTable would not work under this condition and I have to create two onetomany mappings like
    Column -> OnetoMany -> ColumnView <- OnetoMany <- View.
    Am I right in my approach or is there anyother way out to represent such manytomany relationships.

    Why other fields are required in your relationshipt table?
    have only two columns and perform @ManyToMany.
    @JoinTable has to be used only on owning side.
    user (mappedBy ) on the other side
    thanks

  • How to resolve many-to-many join by 2 one-to-many joins

    Hi,
       I was asked many times how to resolve many to many relationship between two tables. I read to use 2 one -to- many relationships to resolve this. Can some expalin me when many to many relationship occurs between two tables and how to reslove them with practicle examples. Is there any article on this?
    Regards,
    Nanda Kishore

    Hi,
    Please check below link.
    http://www.forumtopics.com/busobj/viewtopic.php?p=859029&sid=20d79e3df07b0d8b41aadfbd902bb6b2
    http://blog.oaktonsoftware.com/2011/04/bridge-tables-and-many-to-many.html
    Thanks,
    Amit

  • Once 10.9.1 is loaded onto my MacBook Pro and it has accessed all my files; is there anyway to back out of the relationship?  I don't want my data on iCloud - how do I make that happen?  Many thanks for any help.

    Once 10.9.1 is loaded onto my MacBook Pro and it has accessed all my files; is there anyway to back out of the relationship?  I don't want my data on iCloud - how do I make that happen?  Many thanks for any help.

    Sorry but I know of no way of not backing up for a PC.

  • HOW can i rotate the loop as many lines of multi line container in BPM

    Hi All
    I have to send an idoc to 2 Receivers by spliting the message.
    Based on the occurance of a particular source segments i need to create those many instance of targets.
    IDOC ---> Rec1 (More than one message instance)
         ---> Rec2  (More than one message instance)
    I have taken messages of Receiver into a multi line container1
    and messages of Receiver 2 into another multi line container2.
    HOW can i rotate the loop as many lines of multi line container.
    Thans
    Prasad

    Hi Raj
    There are two webservices are 2 receivers.
    In the idoc there is specific segment , which occurs unbounded,Each occurence we Need to check the value of a particual field and send to corresponding Receiver.
    For Ex:
    ZE1KONH (1..Unbounded)
       >MSFGN =004 --> Rec1
      >> MSFGN==0009 Rec2
    It could be like , 1 or more segm for Rec1 and 1 or more segm for Rec2
                            all are for Rec1 or All are for Rec2.
    so in the tranformation we need to put all message of Rec1 in corresponding multiline container as well for Rec2. Then i need to send to correspongind Receiver.
    So here i need to send all splited messages to appropriate receivers

  • I have microsoft word for for my Mac book pro. When I open saved letters /documents on word the date automactically changes to the current date. How do I stop this happening? Many Thanks

    I have microsoft word for for my Mac book pro. When I open saved letters /documents on word the date automactically changes to the current date. How do I stop this happening? Many Thanks

    I suggest you post your qeustion on the Microsoft Mac forums as it's their software you're having issues with and that's where the MS experts hang out
    http://answers.microsoft.com/en-us/mac

  • Problem in Many-to-Many Associations (JBO-27014 error)

    I am facing a problem during insertion in an Intersection table.
    I have 3 tables Customer, Accounts and Customer_Account. In order to implement the Many to Many relationship between Customer and Accounts, I created an intersection table Customer_Account.
    Table Structure
    CUSTOMER
    Cust_id NUMBER NOT NULL PK
    Name VARCHAR2(50) NOT NULL
    ACCOUNT
    Account_Id NUMBER NOT NULL PK,
    Account_number NOT NULL,
    Sort_Code NUMBER NOT NULL,
    Account_Type VARCHAR2(10) NOT NULL
    CUSTOMER_ACCOUNT
    Cust_Id NUMBER NOT NULL,
    Account_Id NUMBER NOT NULL
    I created an Association CustAcctAsso between Customer and Account with Customer_Account as intersection entity. Then created a viewlink CustAcctViewLink with CustomerView as Source entity, AccountView as Destination entity and selected the CustAcctAsso as association.
    I included this in the application module using the following steps
    Selected AccountView via CustAcctViewLink in the Available view pane and selected CustomerView in Data model pane. Clicked > to add AccountView via CustAcctViewLink as a restricted view.
    Also added CustomerView via CustAcctViewLink as a restricted view.
    When I tried to insert data through the second restricted view I am getting an JBO 27014 Attribute Sort Code in Account is required.
    It would be very helpful if someone gives me a solution quickly.
    Thanks
    Renuka

    Thanks, now I am able to insert data into CUSTOMER and ACCOUNT table, but not in the intersection table.
    It seems that we cannot do any insertion into the intersection table. Please advice me, this is urgent.OK here's what you need to do to insert a new row in both ACCOUNT and INTERSECTION tables.
    1. Create a new viewobject with a join of INTERSECTION and ACCOUNT tables such that both are updateable but ACCOUNT is reference entity.
    -- This is assuming you want to insert a new account when you insert a new account id in the intersection table otherwise, you can make ACCOUNT entity readonly as well.
    2. Create a viewlink between Customer viewobject and this NewViewObject (1-* ViewLink).
    3. If the assumption in step 1 is NOT to update/insert new Accounts form this VO, then you're done. Add the new viewobject usage in your application module and you should be able to use it to edit/insert intersection details.
    Otherwise -
    Set the Updateable flag on AccountID (from the Account entity usage in the NewViewObject) to "never" udpateable.
    Set the Updateable flag on Other attributes from the Account entity usage in the NewViewObject to udpateable-while-new or always as desired.
    4. Select to generate EntityDefImpl subclass for Account table and override the protected method createInstance as below:
      protected EntityImpl createInstance(DBTransaction txn, AttributeList al)
        // TODO:  Override this oracle.jbo.server.EntityDefImpl method
        return super.createInstance(txn, al);
      }5. Select to generate a ViewRowImpl subclass with accessors for this NewViewObject
    6. Add the following logic in setAccountID() method (assuming AccountId attribute is editable and from Intersection entity)
    (Note you'll also have anothe attribute AccountId1 from Account entity which should be readonly as marked in step 3.)
    //get the current intersection entity.
    IntersectionImpl intersection = (IntersectionImpl)getEntity(1);
    setAttributeInternal(ACCOUNTID1, value);
    //if it is same as I added and is not the same as new one
    //framework may assign a new intersection entity based on FK.
    IntersectionImpl newIntersection = (IntersectionImpl)getEntity(1);
    IntersectionDefImpl intersectiondef = (IntersectionDefImpl)IntersectionImpl.getDefinitionObject();
    IntersectionEnrollmentImpl myVO = ((IntersectionEnrollmentImpl)getViewObject());
    DBTransaction dbtxn = myVO.getDBTransaction();
    //see if a intersection exists with this FK
    intersection = (IntersectionImpl)intersectiondef.findByPrimaryKey(dbtxn, IntersectionImpl.createPrimaryKey(value));
    //if this viewrow created a new intersection earlier which is different from
    //the current intersection entity, remove the old one as I created it.
    if ((intersectionAdded != null) && (intersection != intersectionAdded || newIntersection != intersectionAdded))
      if (intersection == null)
        //if I added this intersection as new, reuse-it.
        intersection = intersectionAdded;
        intersection.setIntersectionid(value);
      else
        //if I added this intersection as new, remove it.
        System.out.println(">>>>removing :"+intersectionAdded.getAttribute(0));
        intersectionAdded.remove();
        intersectionAdded = null;
    if (intersection == null)
      //if new intersection is null = no intersection exists with this key, then create a new one.
      intersection = (IntersectionImpl)intersectiondef.createInstance(dbtxn, new AttributeListImpl());
      intersection.setIntersectionid(value);
      intersectionAdded = intersection;
      setEntity(1, intersection);
      myVO.notifyRowUpdated(findRowSetForRow(this), new ViewRowImpl[]{this}, new int[]{2,3});
    else if (intersection != newIntersection)
      //otherwise, create a set the new intersection entity as my intersection entity reference
      setEntity(1, intersection);
      myVO.notifyRowUpdated(findRowSetForRow(this), new ViewRowImpl[]{this}, new int[]{2,3});
    }Now when you insert a new row in this NewViewObject, you can either enter a new Account or refer to an existing Account.
    The setAccountId() method will automatically bring the Account details for existing accounts or create a new Account entity as in the above logic.

  • HT201274 hi, I want to sell my iphone, how can I delete all contents? many thanks

    hi, I want to sell my iphone, how can I delete all contents? many thanks

    Settings > Messages > iMessage > Off
    Settings > FaceTime > Off
    Settings > iCloud > Delete Account
    Settings > General > Reset > Erase All Content and Settings

  • I'm converting from a PC to  iMac. On the PC I have many Inbox folders with PR info for distribution. How do I get these folders from the PC to the iMac?

    I'm converting from a PC to  iMac. On the PC I have many Inbox folders with PR info for distribution. How do I get these folders from the PC to the iMac? I've used the Windows e mail Inbox folders for an easy access filing cabinet for years, as this all goes out on e mail. Thanks for assisting me!

    I think the easiest way would be to use Migration Assistant to get all that over...
    http://support.apple.com/kb/HT2518
    http://support.apple.com/kb/DL1415

  • How to create ViewModel in an MVVM application using entity framework where database has many-to-many relationship?

    I have started developing a small application in WPF. Since I am completely new to it, to start with I took a microsoft's sample available at
    Microsoft Sample Application and following the pattern of the sampke I have been so far successful  in creating four different views for their corresponding
    master tables. Unfortunately, I have got stuck up as the sample does not contain pattern for creating ViewModel when there is a many-to-many relationship in the database. In my application, I have the following data structure:
    1. Table Advocate(advId, Name)
    2. Table Party (partyId, Name)
    3 Table Case (caseId, CaseNo)
    4. Link Table Petitioner (CaseId, PartyId)
    5. Link Table Respondent (CaseId, PartyId)
    6. Link Table EngagedAdvocate(CaseId, advId)
    7. Link Table EngagedSrAdvocate(CaseId, advId)
    In the scenario above, I am a bit confused about how to go forward creating the required ViewModel which would render me to have multiple instances of Petitioners, Respondents, Advocates and SrAdvocates.
    Please explain details in step by step manner considering that whatever work I have completed so far is a replica of Microsoft's sample referred above. I would also like to mention that I have developed my application
    using VB.net. So please provide solution in vb.net.
    After getting many-to-many relationship introduced into my application, it would achieve one level above the sample application and I would like to share with the community so that it could be helpful to many aspiring developers seeking help with MVVM.

    Hi ArunKhatri,
    I would suggest you referring to Magnus's article, it provides an example of how you could display and let the user edit many-to-many relational data from the Entity Framework in a dynamic and data-bound DataGrid control in WPF:
    http://social.technet.microsoft.com/wiki/contents/articles/20719.wpf-displaying-and-editing-many-to-many-relational-data-in-a-datagrid.aspx
    You can learn how to design the ViewModel and the relationship between the entities.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for