CMR Many-to-Many Question

Hi,
I am doing an applicatiion using CMP. I have 2 tables in my database that have a many-to-many unidirectional relationship. Consequently, I have created a link table that takes the primary key value from both tables. It is the standard way for doing it in a relational databse. I have setup CMR fields in my appropriate bean class. My question is, will that link table be updated by the container when I create a new relationship?
I have looked at the folowing code from the IBM website. I think it is a good example.
The addRole() adds a role to a UserBean as follows:
public void addRole(String email, String roleName){
    LocalUser user = userHome.findByPrimaryKey(email);
    LocalRole role = roleHome.findByPrimaryKey(roleName);
    Collection roles = user.getRoles();
    roles.add(role); The author the says "Thus, when a role gets added to the roles collection, the EJB container updates the datastore. Thus, the code that inserts the relationship in the datastore is the interface of the Collection class."
Does he mean that a link table will be updated?
If anyone has tried this could they please let me know.
Thanks,
Chris.

Yeh I know I don't have to write to the database, but when I create my CMP bean I didnt map it to my link table. Therefore I'm not sure if the container will update the link table in my database.

Similar Messages

  • Many-to-Many CMR

    hi all,
    i defined two entity beans, Quiz and Question, with many-to-many cmr and
    a table named Quiz_questions_Question_quizesTable is created in the database after deployment process. the formed table columns consist of primary key of Quiz and primary key of Question, as expected. what i want to do is adding one more column to this table that shows the sequence number of the related question in the related quiz. is it possible? and how? or what should i do?
    thanks in advance..

    "what i want to do is adding one more column to this table that shows the sequence number of the related question in the related quiz."
    Makes sense, but then the association table is no longer just an association table.
    Perhaps a way to get you in the right frame of mind is, "how would you model this with just objects?"
    Basically a CMR just represents an association between two objects. You would see in your revised object model that you do not have a simple n-to-n association between a Quiz objects and a Question objects.[Quiz](0..n)---->(1..n)[Question]The above (bastardized UML) model does not represent the enumeration of Question objects within the scope of a single Quiz object.
    Perhaps the following is more accurate:[Quiz](1)---->(1..n)[QuizQuestion](0..n)---->(1)[Question]or                     [Question]
                              A
                              |
                              |
    [Quiz](1)---->(1..n)[QuizQuestion]It is only after you have your object model that you should worry about the entity bean stuff.

  • Many-to-many mapping question

    Hi,
    I'm working with two classes Car and Customer. The Car class has a Vector of Customers and the Customer class has a Vector of Car. Both are related by a many to many mapping.
    I have noticed that I have to set one of the vector to read only to avoid the error message "More than one writable many-to-many mapping can not use the same relation table" in the mapping workbench.
    I can understand that but is there a way to work around, I mean to be able to add a car to a customer and add a customer to a car with the both vectors?
    Is there something to do with the cache?
    I use Vector for the collection or Map class, have I to do otherwise?

    Hello Vladislav, I understand your first question in this thread, but I'm not sure I follow the rest, so let me respond to your first post:
    "I have noticed that I have to set one of the vector to read only to avoid the error message "More than one writable many-to-many mapping can not use the same relation table" in the mapping workbench.
    I can understand that but is there a way to work around, I mean to be able to add a car to a customer and add a customer to a car with the both vectors?"
    The issue here is that with a Many to Many mapping the mapping is responsible for writing to the association table. So, you have a "CAR_CUST" association table. Imagine you add a Car "101" to a customer "501" and the requisite customer "501" to that car "101" in your object model. Then the association table should only be updated once, with an entry of "101, 501". But since the M-M is mapped in both directions, you need to tell TopLink which of these to consider as the "master" when updating the database.
    If you didn't make one of the M-M mappings "read only", then TopLink would insert "101, 501" twice in the association table, and then at a later date you would see that the customer 501 had two 101 cars!
    We do have a feature that allows for TopLink to maintain bidirectional relationships such that if you add or remove a target from one relationship, TopLink will automatically add/remove it from the opposite direction. In my opinion this is lazy programming! A good Java developer should insist on keeping his model up to date on his own. This feature was added because it's part of the EJB spec, not necessarily because it's a good idea ;)
    - Don
    Is there something to do with the cache?
    I use Vector for the collection or Map class, have I to do otherwise?

  • Making a Many to Many CMR in Netbeans

    Anyone have any clue how to do this?
    I have the classic three tables:
    create table user (
    id integer,
    name varchar(30)
    create table role (
    id integer,
    name varchar(30)
    create table userrole (
    userid integer,
    roleid integer
    I use NB 5 to create the User and Role beans from the Database. Then I go in to the ejb-jar.xml visual editor, create a CMR that's Many to Many, UserBean to RoleBean, create a CMR field in UserBean names roles. I leave "create CMR field" for RoleBean unchecked.
    Then I go to sun-cmp-mappings.xml and open up its editor.
    Click on UserBean, see the CMP fields all mapped. On the roles field, I click the Mapped Column drop down box and select "map relationship field". This pops up a new wizard, but I can't get Next to light up, and there's nothing in the Related Bean column of fields, and they're disabled so I can not change them.
    So, I'm kind of stuck at this point and curious if someone can step me through creating this relationship.

    With Netbeans 5.5 that's very easy, if you do not encounter bugs (it is a preview release):
    Just anotate your beans :
    class User {
    @ManyToMany(mappedBy="members")
    public Collection<Role> getRoles(){
    class User {
    @ManyToMany
    public Collection<User> getMembers(){
    Then the application server will create the tables for you

  • BC4J - Many-to-Many Question

    I have modeled in a bc4j project a many to many relationship between AUTHOR and BOOK using an association table BOOK_AUTHOR.
    My BC4J objects to model this are:
    - 3 entity objects (BOOK,AUTHOR,BOOK_AUTHOR)
    - 1 many-to-many association (book_author_association)
    - 2 view objects (book_view,author_view)
    - 1 many-to-many viewlink (BookAuthorViewLink)between book_view and author_view.
    - 1 app_module with all the correct vo/viewLinks added.
    - I have also created the row/vo interfaces for all of my client methods.
    So my questions are:
    (1)What is the best way to add an author to a book?
    I’ve tried doing it in the bc4j tester and it only adds to the author table not the association table. I’ve also tried the following code in my BookViewRowImpl:
    public AuthorViewRow createEmp(String name) {
              AuthorViewRow newAuthor = (AuthorViewRow) getAuthorView().createRow();
              getAuthorView().insertRow(newAuthor);
              newAuthor.setAuthorNam(name);
              return newAuthor;

    I've had the same problem.
    I'solved it using three different views. In your case there is a view "AuthorsView", a "BooksView" and a "AuthBookRelationsView", all of them connected with the appropriate one-to-many Associations and ViewLinks.
    Creating a new many-to-many Association means first creating or selecting the corresponding rows in "BooksView" and "AuthorsView" and then inserting the correspondig row into the "AuthBookRelationsView".
    The many-to-many association or the many-to-many view can only be used for reading, but not for creating a new many-to-many association.
    Don't know if this is the best way to do, but however, it works! I think that BC4J might have been a little bit smarter here...
    By the way, I'm using a cascading delete constraint on both associations to the intersection table. This results in both associations being composite associations, which itself is a source of a lot of trouble with BC4J. But however, it is quite useful as I do not have to bother with maintaining the intersection table once one of the master entities is deleted. Please ask, if you need more details...

  • Many "many-to-many-" questions ;)

    Hello everyone,
    1 - I am trying to use two many-to-many transactions on the same page. Everything seems to be working except that the supplemental fields are not inserting or updating into the database. No error is being returned.
    2 - Is there a way to validate the data that is being entered via these supplemental fields? I want to check that any item that is checked actually has a cost entered for it.
    Thanks for any help you can provide.
    A Read

    OK.. so I have figured out the problem with the first part of my question.<br /><br />It seems that there is a bug in the ADDT many-to-many wizzard when there are more than one of them in a form.<br /><br />The first transaction is referred to in all of the code as mtm_<whatever the fields are>, subsequent fields are referred to as mtm1_<whatever the fields are>, mtm2_<whatever the fields are>, etc.<br /><br />It seems that the wizzard does a good job of re-numbering all of these EXCEPT when it comes to the form's boxes name and id for any supplemental fields.  I had to re-number them from mtm_<blah blah> to mtm1_<blah blah> and now they work...<br /><br />Now onto the second part of my question.<br /><br />A Read

  • Many-to-many question

    Just asking for some help with some search terms, as I know that this topic has been argued out somewhere. I just haven't been able to find it:
    If I'm setting up a cross-reference/junction table in order to fulfill a many-to-many requirement, should I create a technical key as a primary key with a unique index on the combined foreign keys? Or should I make the combination of the foreign keys the primary key?
    Our newest standards force a technical key on all tables, and one of the Developers is asking why that's necessary on a cross-reference table. I've searched on "cross reference table primary key", "junction table primary key". Most answers suggesting a technical key are due to database performance issues that can be solved with it (not suggested for that reason for Oracle that I've found yet).
    --=Chuck

    >
    If I'm setting up a cross-reference/junction table in order to fulfill a many-to-many requirement, should I create a technical key as a primary key with a unique index on the combined foreign keys? Or should I make the combination of the foreign keys the primary key?
    >
    Assuming that each of your foreign keys is a surrogate key and not an actual data value, I have to agree with Dan on this one.
    The two primary attributes that a key value should have are: 1) it should be unique and 2) it should have no inherent meaning.
    By 'no inherent meaning' I mean it should NOT be a data value or have any meaning whatsoever attached to its value. If the value were to change it would have no impact at all on the actual data though naturally the value has to be changed the same everywhere it is used.
    A classic example in the U.S. is social security number. It should NOT be used as a key even though it might be considered a 'natural' key.
    The value is a data item that has meaning and is subject to change if for no other reason than typographical error. It is the problems involved in making changes to data items used as keys that surrogate keys are intended to prevent.
    A surrogate key (even a sequence) has no inherent meaning. If a value of 2 is being used in a system and, unknown to you, someone changes the value to a 3 everywhere in your system that it is used you will never notice it.
    I have seen no standard suggesting that multi-column surrogate keys are inappropriate. Your intersect table can use the combination of the foreign keys as the primary key and fulfill the contract of using surrogate keys.
    Sven suggested this
    >
    For example you later discover that you want a detail table for your joined table. Then the detail table would need only one column as a foreign key constraint, instead of two (which can have major performance implications).
    >
    If if was desired to meet that future requirement by using one column you can easily do so by adding a new column specifically for that purpose without any impact whatsoeve on the existing system.
    As for this possible architecture change
    >
    Or you add some third column to include into the uniqueness logic.
    >
    Well that requirement is a fundamental change to your existing one. The existing requirement is that the combination of the two foreign keys should be unique. It is not clear if Sven was suggesting that that requirement is no longer valid or if rather suggesting that there is no an ADDITIONAL requirement that those two values as well as a third should also be unique.
    If you need to implement uniqueness for the two values you currently have as well as for those combined with a third value that would be better implemented by creating yet another INTERSECT table specifically for that purpose and leave the existing intersect table in place. That architecture approach expands the data model without disrupting the existing one.
    The main design goal, in my opinion, should always be to produce a design which most easily meets current requirements without foreclosing the ability to meet unknown future requirements.

  • Many-to-many relationship question

    Hello,
    Could you please provide an EXAMPLE of sun-cmp-mappings.xml with many-to-many relations (using a secondary table).
    Thanks.

    I think it is important to make the distinction between the mapping of many-to-many relations (join tables) and secondary tables.
    There is a many to many mapping in the samples. The roster sample has it. You can read through the sun-cmp-mappings.xml file for that to see how to do a join table. The fields that you want to look at are Player's teams field and Team's players field.
    The secondary table allows you to map columns from multiple tables into a single entity bean. For example:
    I may have an Address bean with the usual fields; street, city, state, and postal/zip code.
    I may need to map this Bean onto a database with the following tables
    ADDR
    STRT_KEY,
    ZIP_KEY
    and
    STRT
    STRT_KEY,
    STRT_STRING
    ZIP
    ZIP_KEY,
    CITY_STRING,
    STATE_STRING
    In my mapping for the Address bean's zip field, the mapping would need to look like:
    <entity-mapping>
    <ejb-name>Address</ejb-name>
    <table-name>ADDR</table-name>
    <cmp-field-mapping>
    <field-name>city</field-name>
    <column-name>ZIP.CITY_STRING</column-name>
    </cmp-field-mapping>
    <secondary-table>
    <table-name>ZIP</table-name>
    <column-pair>
    <column-name>ADDR.ZIP_KEY</column-name>
    <column-name>ZIP.ZIP_KEY</column-name>
    <column-pair>
    </secondary-table>
    The secondary table element defines join between the two tables, so the field can resolve to a single value.

  • QUESTION:  HOW TO WRITE QUERY  WITH MANY TO MANY RELATIONSHIPS

    Could someone help me out here?
    I was sitting here looking at some tables ie table_name and synonyms and wondering.
    If a table can belong to many synonyms and a synonym can belong to many tables how would one write a query where I would like to know which tables belong to each synonym or on the other hand which synonym belongs to what tables?
    Would I try to develop an outside join for this, a corrolated query or a query with a subquery or would there be another format that would work better?
    What would be the best method of attack on this?
    Thanks for your thoughts on this.
    al

    Actually, the relationship is not many to many. A table can have many synonyms, but a synonym within a namespace (i.e. a PUBLIC synonym, or a private synonym created by a user) can only point to one table. The xxx_synonmys tables already contain the information about the table_name and table_owner.
    John

  • 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 can I establish many to many unidirectional relationship?

    Hi, EJB Fans!
    I am an ejb fan too.
    This time I am learn ejb2.0 and find very funny in cmr. I think it is a good idea and can do manythings we cann't do or difficult with ejb1.1.
    But in many to many relationship, I don't know how to give my tables to entity A and entity B. How can I define tables to make A contains related Bs' information? And so do B. But i think make this table is difficult, because we don't know exactly how many should contains? And this is an examples:
    Difine entity A as User, and B as roles such as Administration, user, power user, as we often used in network. A user can have many roles, and roles can allocated to many roles.
    Another examples is entity A as person, and B as Department. B container A, and A can join many department as he or she can.
    B can find A(s) with which clues?? Methods like this java.util.Collection getAs()
    , this collection how can ejb container caculate it out?
    It is very myth, even wonderful!
    I love java and more like ejbs.

    No body reply.
    My question is silly or my english is very bad.
    Sorry I am chinese-speaking programmer.

  • Many to Many Relationships in ejb.....Urgent Pls help

    hi all,
    Am working in EJB.Now we are coding for many to many relationship.
    Company and Salary register
    One Company can have many salary register and More than one company can have one salary register
    Companyand Salary register are the two tables having details of it.And the intermediate table having pk of company and salary register is Company_salary_register table,I want to add the value in this table having seperate interface.
    How to model it? I have given the add method of this company_salary_register table in company bean.I am getting the value of this one as collection.But it is asking me to add the values as the instance of LocalSalary(interfaceand entitybean).If i type cast it as Local Salary Class castexception occurs
    Please help me.Even Material of Modelling Many to Many relationship in EJB is enough.
    thanx in advance,

    THaaaaaanks alottt for the quick reply...
    I used the first way to insert the document and i was successful...
    but thing is that..
    when i do
    SQL>desc message_type
    message_type is NOT FINAL
    Name Null? Type
    SYS_XDBPD$ XDB.XDB$RAW_LIST_T
    to VARCHAR2(4000 CHAR)
    from VARCHAR2(4000 CHAR)
    subject VARCHAR2(4000 CHAR)
    body VARCHAR2(4000 CHAR)
    i can see the structure...
    and when i
    select count(*) from messages
    it says count is 1.
    so how to know where the data is ..like below in the data :
    'to' it has '[email protected]'
    and for 'from' it has '[email protected]'..and so on..
    <message>
    <to>[email protected]</to>
    <from>[email protected]</from>
    <subject>Question</subject>
    <body>Does this demo work?</body>
    </message>
    so what is the command to get that data...
    because when i do
    select * from message_type..it says
    select * from message_type
    ERROR at line 1:
    ORA-04044: procedure, function, package, or type is not allowed here
    Plss help me outt.......this will be my final step...
    Thankssssssssssssssss

  • Many to many relationship mapping.

    Hi
    I have a basic question on how to create a good java class model (POJOs) based on the database model.
    I Have to follwing tables
    Table1 with columns as
    ID1
    name
    description
    Table2 with columns as
    ID2
    dateCreated ..etc.
    Since there is a many to many relationship between table1 and table2
    So to map that we have a table3 with columns
    ID3
    ID1 // fk table1
    ID2 // fk table2
    browserName
    startTime
    endTime
    So when I create Java classes:
    // corresponding to table 1
    Class MyTable1
    private Integer ID1;
    private List ID2; // to map with the table2
    // corresponding to table 2
    Class MyTable2
    private Integer ID2
    private List ID1; // to map with table 1
    In this way I can create my classes. Is this the best way to put it together.
    And where to put the attributed specific to table3. Like the BrowserName and the StartTime and the EndTime.
    Any suggestion please.
    Thanks.

    Your names leave a lot to be desired. Let's start with an example. Suppose I have a problem involving employees and the tasks assigned to them. An employee may have any number of tasks assigned to them and a task can be assigned to any number of employees. The assignment itself has more attributes: when it was assigned, its priority and so on.
    public interface Employee {
        Long getId(); //etc...
        Set<Assignment> getAssignments();
        void setAssignments(Set<Assignment> assignments);
    public interface Task {
        Long getId(); //etc...
        Set<Assignment> getAssignments();
        void setAssignments(Set<Assignment> assignments);
    public interface Assignment {
        Long getId(); //etc...
        Employee getEmployee();
        void setEmployee(Employee employee);
        Task getTask();
        void setTask(Task task);
    }This assumes you want to navigate in all directions: from an employee to their assignments, from a task to its assignments and from an assignment to it employee and task.

  • Defining a many-to-many relationship with CMP EJBs  : does it work for you

    Curious to know whether someone has been able to set up a many to many relationship between two entity beans.
    I have been struggling with this for days now and I can't get it to work.
    In my test project I have two entity beans, resp. Consultant and Solution.
    Consultant has a cmr field called 'solutions', which is a collection object from the opposite side (Solution).
    This is the source of the ejb-jar.xml file
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
    <ejb-jar>
         <description>EJB JAR description</description>
         <display-name>EJB JAR</display-name>
         <enterprise-beans>
              <session>
                   <ejb-name>ProfilerBean</ejb-name>
                   <home>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerHome</home>
                   <remote>com.atosorigin.tcc.testing.ejbses.profiling.Profiler</remote>
                   <local-home>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerLocalHome</local-home>
                   <local>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerLocal</local>
                   <ejb-class>com.atosorigin.tcc.testing.ejbses.profiling.ProfilerBean</ejb-class>
                   <session-type>Stateless</session-type>
                   <transaction-type>Container</transaction-type>
                   <ejb-local-ref>
                        <ejb-ref-name>EJBTesting/Solution</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocalHome</local-home>
                        <local>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocal</local>
                        <ejb-link>SolutionBean</ejb-link>
                   </ejb-local-ref>
                   <ejb-local-ref>
                        <ejb-ref-name>EJBTesting/Consultant</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocalHome</local-home>
                        <local>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocal</local>
                        <ejb-link>ConsultantBean</ejb-link>
                   </ejb-local-ref>
              </session>
              <entity>
                   <ejb-name>ConsultantBean</ejb-name>
                   <home>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantHome</home>
                   <remote>com.atosorigin.tcc.testing.ejbcmp.profiling.Consultant</remote>
                   <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocalHome</local-home>
                   <local>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantLocal</local>
                   <ejb-class>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Consultant</abstract-schema-name>
                   <cmp-field>
                        <field-name>firstname</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>lastname</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>country</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>id</field-name>
                   </cmp-field>
                   <primkey-field>id</primkey-field>
                   <query>
                        <query-method>
                             <method-name>findBySolution</method-name>
                             <method-params>
                                  <method-param>java.lang.String</method-param>
                             </method-params>
                        </query-method>
                        <ejb-ql>SELECT Object(c) FROM Consultant AS c,
                        IN(c.solutions) s WHERE s.id = ?1 </ejb-ql>
                   </query>
              </entity>
              <entity>
                   <ejb-name>SolutionBean</ejb-name>
                   <home>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionHome</home>
                   <remote>com.atosorigin.tcc.testing.ejbcmp.profiling.Solution</remote>
                   <local-home>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocalHome</local-home>
                   <local>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionLocal</local>
                   <ejb-class>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionBean</ejb-class>
                   <persistence-type>Container</persistence-type>
                   <prim-key-class>java.lang.String</prim-key-class>
                   <reentrant>False</reentrant>
                   <cmp-version>2.x</cmp-version>
                   <abstract-schema-name>Solution</abstract-schema-name>
                   <cmp-field>
                        <field-name>description</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>name</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>parent</field-name>
                   </cmp-field>
                   <cmp-field>
                        <field-name>id</field-name>
                   </cmp-field>
                   <primkey-field>id</primkey-field>
                   <query>
                        <query-method>
                             <method-name>findChildSolutions</method-name>
                             <method-params>
                                  <method-param>java.lang.String</method-param>
                             </method-params>
                        </query-method>
                        <ejb-ql>SELECT Object(s) FROM Solution AS s WHERE
                        s.parent = ?1</ejb-ql>
                   </query>
                   <query>
                        <query-method>
                             <method-name>findTopLevelSolutions</method-name>
                             <method-params/>
                        </query-method>
                        <ejb-ql>Select Object(s) FROM Solution AS s WHERE
                        (s.parent = &apos;none&apos;)</ejb-ql>
                   </query>
              </entity>
         </enterprise-beans>
         <relationships>
              <ejb-relation>
                   <description>A consultant may have one or more areas of expertise</description>
                   <ejb-relation-name>Consultant_Solutions</ejb-relation-name>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>com.atosorigin.tcc.testing.ejbcmp.profiling.ConsultantBean</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <relationship-role-source>
                             <ejb-name>ConsultantBean</ejb-name>
                        </relationship-role-source>
                        <cmr-field>
                             <cmr-field-name>solutions</cmr-field-name>
                             <cmr-field-type>java.util.Collection</cmr-field-type>
                        </cmr-field>
                   </ejb-relationship-role>
                   <ejb-relationship-role>
                        <ejb-relationship-role-name>com.atosorigin.tcc.testing.ejbcmp.profiling.SolutionBean</ejb-relationship-role-name>
                        <multiplicity>Many</multiplicity>
                        <relationship-role-source>
                             <ejb-name>SolutionBean</ejb-name>
                        </relationship-role-source>
                   </ejb-relationship-role>
              </ejb-relation>
         </relationships>
         <assembly-descriptor>
              <container-transaction>
                   <description>container-transaction</description>
                   <method>
                        <ejb-name>SolutionBean</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <method>
                        <ejb-name>ProfilerBean</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <method>
                        <ejb-name>ConsultantBean</ejb-name>
                        <method-name>*</method-name>
                   </method>
                   <trans-attribute>Required</trans-attribute>
              </container-transaction>
         </assembly-descriptor>
    </ejb-jar>
    I created a stateless session bean as a business facade for the two entity beans. I then created a webservice to test the beans.
    What works :
    - create a consultant
    - get a consultant
    - create a solution
    - get a solution
    (basically everything that doesn't involve the relationship field.
    However, what doesn't work is the method call assignSolution:
    - assign solution : this is implemented as follows
    Business Method.
         public void assignSolution(String consultantID, String solutionID)
              throws ProfilingException {
              // TODO : Implement
              ConsultantLocal cons = null;
              SolutionLocal sol = null;
              try {
                   cons = consHome.findByPrimaryKey(consultantID);
                   sol = solHome.findByPrimaryKey(solutionID);
                   Collection solutions = cons.getSolutions();
                   solutions.add(sol);
                   //sol.getConsultants().add(cons);
              } catch (FinderException ex) {
                   ex.printStackTrace();
                   throw new ProfilingException("failed to retrieve data from DB", ex);
    As you can see I am trying to use the CM Relationship in this methhod. Adding the solution to a consultant should be as simple as adding a solution object to the collection retrieved with the getSolutions accessor. The Container is expected to persist the information in my MAXDB database.
    However this doesn't happen.
    The ORM details as defined in the persistent.xml follows :
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE persistent-ejb-map SYSTEM "persistent.dtd">
    <persistent-ejb-map>
         <locking
              type="Table"/>
         <db-properties>
              <data-source-name>TCC_PORTAL_PROFILER</data-source-name>
              <database-vendor
                   name="SAPDB"/>
         </db-properties>
         <entity-beans>
              <entity-bean>
                   <ejb-name>ConsultantBean</ejb-name>
                   <table-name>PFL_CONSULTANTS</table-name>
                   <field-map
                        key-type="NoKey">
                        <field-name>firstname</field-name>
                        <column>
                             <column-name>FIRSTNAME</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>lastname</field-name>
                        <column>
                             <column-name>LASTNAME</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>country</field-name>
                        <column>
                             <column-name>COUNTRY</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="PrimaryKey">
                        <field-name>id</field-name>
                        <column>
                             <column-name>ID</column-name>
                        </column>
                   </field-map>
                   <finder-descriptor>
                        <method-name>findBySolution</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                        <load-selected-objects
                             lock="read"/>
                   </finder-descriptor>
              </entity-bean>
              <entity-bean>
                   <ejb-name>SolutionBean</ejb-name>
                   <table-name>PFL_SAPSOLUTIONS</table-name>
                   <field-map
                        key-type="NoKey">
                        <field-name>description</field-name>
                        <column>
                             <column-name>DESCRIPTION</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>name</field-name>
                        <column>
                             <column-name>NAME</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="NoKey">
                        <field-name>parent</field-name>
                        <column>
                             <column-name>PARENTID</column-name>
                        </column>
                   </field-map>
                   <field-map
                        key-type="PrimaryKey">
                        <field-name>id</field-name>
                        <column>
                             <column-name>ID</column-name>
                        </column>
                   </field-map>
                   <finder-descriptor>
                        <method-name>findChildSolutions</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                        <load-selected-objects
                             lock="read"/>
                   </finder-descriptor>
                   <finder-descriptor>
                        <method-name>findTopLevelSolutions</method-name>
                        <method-params/>
                        <load-selected-objects
                             lock="read"/>
                   </finder-descriptor>
              </entity-bean>
         </entity-beans>
         <relationships>
              <table-relation>
                   <help-table>PFL_CONS_SOL_MAP</help-table>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>ConsultantBean</ejb-name>
                        <cmr-field>solutions</cmr-field>
                        <fk-column>
                             <column-name>CONSULTANTID</column-name>
                             <pk-field-name>id</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>SolutionBean</ejb-name>
                        <fk-column>
                             <column-name>SOLUTIONID</column-name>
                             <pk-field-name>id</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
              </table-relation>
         </relationships>
    </persistent-ejb-map>
    The error in the default trace file when calling the method states, there is an "inconsistency in the number of primary keys". Details follow.
    #1.5#000F1F188E5C004400000000000010480003E76C80EFD57A#1098880364327#com.sap.engine.services.ejb#com.atosorigin.tcc/EJBCMPProfilingTest#com.sap.engine.services.ejb#Guest#2####4d2b2370281411d9a40d000f1f188e5c#SAPEngine_Application_Thread[impl:3]_31##0#0#Error##Java###
    [EXCEPTION]
    #1#com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception in method assignSolution.
         at com.atosorigin.tcc.testing.ejbses.profiling.ProfilerObjectImpl0.assignSolution(ProfilerObjectImpl0.java:822)
         at com.atosorigin.tcc.testing.ejbses.profiling.Profiler_Stub.assignSolution(Profiler_Stub.java:533)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sap.engine.services.ejb.session.stateless_sp5.ObjectStubProxyImpl.invoke(ObjectStubProxyImpl.java:187)
         at $Proxy73.assignSolution(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at com.sap.engine.services.webservices.runtime.EJBImplementationContainer.invokeMethod(EJBImplementationContainer.java:126)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:146)
         at com.sap.engine.services.webservices.runtime.RuntimeProcessor.process(RuntimeProcessor.java:68)
         at com.sap.engine.services.webservices.runtime.servlet.ServletDispatcherImpl.doPost(ServletDispatcherImpl.java:92)
         at SoapServlet.doPost(SoapServlet.java:51)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:385)
         at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:263)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:339)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:317)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:810)
         at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:238)
         at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
         at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:147)
         at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:37)
         at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:94)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:162)
    Caused by: com.sap.engine.services.applocking.exception.SAPAppLockingIllegalArgumentException: Inconsistency in number of primary keys
         at com.sap.engine.services.applocking.TableLockingImpl.getArgument(TableLockingImpl.java:385)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:128)
         at com.sap.engine.services.applocking.TableLockingImpl.lock(TableLockingImpl.java:138)
         at com.sap.engine.services.ejb.entity.pm.lock.TableLockingSystem.write(TableLockingSystem.java:82)
         at com.sap.engine.services.ejb.entity.pm.PersistentM2M.create(PersistentM2M.java:172)
         at com.sap.engine.services.ejb.entity.pm.PersistentCacheM2M.add(PersistentCacheM2M.java:197)
         at com.sap.engine.services.ejb.entity.pm.multiple.CollectionM2M.add(CollectionM2M.java:57)
         at com.atosorigin.tcc.testing.ejbses.profiling.ProfilerBean.assignSolution(ProfilerBean.java:201)
         at com.atosorigin.tcc.testing.ejbses.profiling.ProfilerObjectImpl0.assignSolution(ProfilerObjectImpl0.java:771)
         ... 32 more
    I can't figure out what the problem is with the ORM mapping defined.
    On the database level I have three tables. Consultant maps to PFL_CONSULTANT, Solution to PFL_SAPSOLUTIONS. The third table PFL_CONS_SOL_MAP is the help table used for the relationship (having two fields, which are in fact foreign keys from the other two tables to express the assignment of solutions to consultants (where a consultant can have one or more solutions).
    ps. : I am running Netweaver Developer Workplace (Netweaver 2004, at stack level 5)
    Message was edited by: Theo Paesen

    Hm, after disabling 'automatic locking' it works.

  • [ADF] Adding/deleting entries in a many-to-many relationship

    I am using JDeveloper 10.1.3 and the ADF BC / ADF Model / ADF Faces / JSF technology stack.
    For this question, I am using the SRDemo application as an example, specifically the many-to-many relationship between USERS and PRODUCTS (the Staff Expertise relationship), outlined in red in this schema diagram: Image Link
    Users may have any number of product expertise areas and many users may have the same product expertise area. For the purposes of this example I have added two reference fields from the PRODUCT table into the ExpertiseAreas VO (Name and Description), outlined in red in this data control palette section: Image Link
    I have created a page which shows the details of a user (1), along with a table showing the expertise areas the user has (3), and a table of all the products available (2), numbered on this design page: Image Link and corresponding to the numbered data controls on this data control palette section: Image Link, where 1 is rendered as an ADF Read-only Form, 2 is an ADF Read-only Table with a tableSelectMany element in the selection facet, and 3 is also an ADF Read-only Table.
    What I am trying to do is have the tableSelectMany element reflect which of the products are linked to the current user in the expertise areas relationship (by having the checkbox for currently linked products checked), and when you check or uncheck a product's checkbox, it should add or remove the row in the EXPERTISE_AREAS intersection table, respectively (asume for this example that there are default values for Expertise Level and Notes).
    So far I have been following the process used in section 19.8 of the ADF Developer's Guide for Forms/4GL Developers, which describes how to set up a selectManyShuttle which implements the adding and deleting functionality. So I have a Client Interface method in the Application Module, updateSkillsForCurrentStaff (described in section 10.6.7.2), and I have a selection listener for the assignment table in the backing bean for the page, which calls the updateSkillsForCurrentStaff method:
    public void selectionChanged(SelectionEvent event)
      BindingContainer bc = getBindings();
      DCIteratorBinding productsIB = (DCIteratorBinding)bc.get("ProductListIterator");
      Set keys = getTable1().getSelectionState().getKeySet();
      Iterator iter = keys.iterator();
      List productIds = new Vector();
      while (iter.hasNext())
        String product = ((Key)iter.next()).toStringFormat(true);
        productsIB.setCurrentRowWithKey(product);
        ViewRowImpl productRow = (ViewRowImpl)productsIB.getCurrentRow();
        Number productId = (Number)productRow.getAttribute("Id");
        productIds.add(productId);
      OperationBinding ob = bc.getOperationBinding("updateSkillsForCurrentStaff");
      Map pm = ob.getParamsMap();
      pm.put("productIds", productIds);
      ob.execute();
    All of this works, but I can't work out how to link the selection state of the assignment table to the expertise areas that are linked to the user. Also I think the method listing above must be a bit of a hack, but I don't know enough about this to know if there's an easier way of doing it.
    Any help is appreciated.

    Have a look at this example I cooked up for you.
    http://radio.weblogs.com/0118231/2006/10/03.html#a739
    It might not be the first way one thinks to implement something, but it illustrates a very interesting, model-centric approach to the problem you propose.
    My feelings won't be hurt if you prefer a more view-centric approach, but I wanted to illustrate what was a maximally-model-centric solution (in fact, which doesn't even require a backing bean!) If you like a more view-centric approach, I can help you figure out what's wrong with your key-handling above. For one, I would probably start by passing the Set of Key's directly to the middle tier application module method to eliminate client-side code.
    Check it out and let me know what you think. Try it directly in the Business Components Tester to appreciate one of the benefits a model-centric solution can bring.

Maybe you are looking for

  • Application Aliases & SSO

    Question 1: In version 2.0, will the issue with duplicate Application Aliases over multiple workspaces (on the same server) be addressed or is there reasoning why there is no validation to prohibit duplication of application aliases? Question 2: Sing

  • Tax code in PO

    I should change tax code in PO's for some materials. So i tried to change it from info records. But system is issuing the message ; Entry  V1  does not exist in T007A - check your entry Message no. 00058 But it is not an incorrect entry. i can see it

  • Question about cont function

    HI all desc table rg_types LIDER number(5), SERIAL_N number(8), CODE_T number(3) TYPE_I number (1), SHIPMENT_NUM number(4) no p.k on table or unique index. TYPE_I can contain values range [0-5]. for every lider can be sug_i [0-5] , select * from rg_t

  • Passing Parameter from URL to Web Forms - Oracle 10 Application Server

    Hi All - I want to pass parameter from a URL to 10g Oracle Web Forms - Oracle Application Server 10.1.2 http://server1/forms/frmservlet?config=SATWEB_SSO&otherparams=username_sso=BABUS How to receive this 'username_sso' value inside my forms applicat

  • Menus pop up when typing the same word in Koteri

    When I type Japanese words again and again, a menu pops up with the kanji that I've used previously. How do I select this word from the menu so I don't have to keep typing? I've clicked on the word, and it doesn't do any good.