Problem with a 1:M relationship between two entity beans

I am having trouble trying to implement a 1:M relationship between two EJB2.0 entity beans using and EJBQL query. I have an ApplicantEJB, which contains a collection of phone numbers. The applicant table in the database has one primary key, applicant_id. The applicant_phones database table has a compound primary key--applicant_id and phone_type_id--so I have implemented a custom PK class to represent this, PhonePK. I have implemented a findByNameAndPhone method in my ejb-jar.xml file with the following syntax:
SELECT object(a) FROM applicants a, applicant_phones p where a.applicantID = p.applicantID and a.name = ?1 and p.phoneNumber = ?2
If I deploy this, Orion/OC4J translates the query in the orion-ejb-jar.xml with an incorrect reference to the applicant_phones.applicant_id column:
SELECT a.applicant_id FROM applicants a , applicant_phones p WHERE ((a.applicant_id = p.applicantID ) AND (a.name = ?) AND (p.phone_number = ? ))
I must have something wrong with the ApplicantEJB and PhoneEJB primary key mappings in my orion-ejb-jar.xml file, but I have tried many different combinations of values and keep getting them overwritten by the container with each deployment. Why is Orion/OC4J defaulting the applicant_id reference to the ob[i]Long postings are being truncated to ~1 kB at this time.

I have posted excerpts from my orion-ejb-jar.xml file in this posting: Problem mapping a 1:M relationship between two entity EJBs w/ a compound PK
Sorry for the duplicate postings, but I was getting errors on the submission.
April

Similar Messages

  • Problem mapping a 1:M relationship between two entity EJBs w/ a compound PK

    I am having trouble trying to implement a 1:M relationship in OC4J 9.0.3 between two EJB2.0 entity beans using an EJBQL query. I have an ApplicantEJB, which contains a collection of phone numbers. The applicant table in the database has one primary key, applicant_id. The applicant_phones database table has a compound primary key--applicant_id and phone_type_id--so I have implemented a custom PK class to represent this, PhonePK. I have implemented a findByNameAndPhone method in my ejb-jar.xml file with the following syntax:
    SELECT object(a) FROM applicants a, applicant_phones p where a.applicantID = p.applicantID and a.name = ?1 and p.phoneNumber = ?2
    If I deploy this, Orion/OC4J translates the query in the orion-ejb-jar.xml with an incorrect reference to the applicant_phones.applicant_id column:
    SELECT a.applicant_id FROM applicants a , applicant_phones p WHERE ((a.applicant_id = p.applicantID ) AND (a.name = ?) AND (p.phone_number = ? ))
    I must have something wrong with my ApplicantEJB and PhoneEJB primary key mappings in my orion-ejb-jar.xml file, but I have tried many different combinations of values and keep getting them overwritten by the container with each deployment. Why is Orion/OC4J defaulting the applicant_id reference Long postings are being truncated to ~1 kB at this time.

    Sure. Here's the <entity-deployment> for my applicant entity:
    <entity-deployment name="ApplicantEntityEJB" location="ApplicantEntityEJB" table="applicants" data-source="java:/OracleDS">
    <primkey-mapping>
    <cmp-field-mapping name="applicantID" persistence-name="applicant_id"/>
    </primkey-mapping>
    <cmp-field-mapping name="name" persistence-name="name"/>
    <cmp-field-mapping name="phones">
    <collection-mapping table="applicant_phones">
    <primkey-mapping>
    <cmp-field-mapping name="applicantID">
    <entity-ref home="ApplicantEntityEJB">
    <cmp-field-mapping name="applicantID" persistence-name="applicant_id"/>
    </entity-ref>
    </cmp-field-mapping>
    </primkey-mapping>
    <value-mapping type="test.entity.PhoneEntity">
    <cmp-field-mapping>
    <entity-ref home="PhoneEntityEJB">
    <cmp-field-mapping>
    <fields>
    <cmp-field-mapping name="phoneTypeID" persistence-name="phone_type_id"/>
    <cmp-field-mapping name="applicantID" persistence-name="app[i]Long postings are being truncated to ~1 kB at this time.

  • Problem with 1-to-many relationship between entity beans

    Hi All!
    I have two tables TMP_GROUP and TMP_EMPLOYEE with following fields:
    TMP_GROUP: ID, CAPTION, COMMENT, STATUS.
    TMP_EMPLOYEE: ID, LOGIN, GROUP_ID.
    For this tables i create two entity beans GROUP and EMPLOYEE respectively.
    The relationship looks like this
    descriptor ejb.xml:
    <ejb-relation>
                <description>description</description>
                <ejb-relation-name>employeesOfGroup</ejb-relation-name>
                <ejb-relationship-role>
                    <ejb-relationship-role-name>com.mypackage.GroupBean</ejb-relationship-role-name>
                    <multiplicity>One</multiplicity>
                    <relationship-role-source>
                        <ejb-name>GroupBean</ejb-name>
                    </relationship-role-source>
                    <cmr-field>
                        <cmr-field-name>employees</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.mypackage.EmployeeBean</ejb-relationship-role-name>
                    <multiplicity>Many</multiplicity>
                    <relationship-role-source>
                        <ejb-name>EmployeeBean</ejb-name>
                    </relationship-role-source>
                </ejb-relationship-role>
            </ejb-relation>
    descriptor persistent.xml:
    <table-relation>
                   <table-relationship-role
                        key-type="PrimaryKey">
                        <ejb-name>GroupBean</ejb-name>
                        <cmr-field>employees</cmr-field>
                   </table-relationship-role>
                   <table-relationship-role
                        key-type="NoKey">
                        <ejb-name>EmployeeBean</ejb-name>
                        <fk-column>
                             <column-name>GROUP_ID</column-name>
                             <pk-field-name>ejb_pk</pk-field-name>
                        </fk-column>
                   </table-relationship-role>
              </table-relation>
    Now i implement business method:
    public Long addEmployee(String login, long groupId) {
              Long result;
              try {
                   EmployeeLocal employee = employeeHome.create(login);
                   GroupLocal group =
                        groupHome.findByPrimaryKey(new Long(groupId));
                   Collection employees = group.getEmployees();
                   employees.add(employee);
                   result = (Long) employee.getPrimaryKey();
              } catch (CreateException ex) {
                   result = new Long(0);
              } catch (FinderException ex) {
                   result = new Long(0);
              return result;
    When i call this method from web service, the following exception is raised:
    com.sap.engine.services.ejb.exceptions.BaseTransactionRolledbackLocalException: Exception in method com.mypackage.GroupLocalHomeImpl0.findByPrimaryKey(java.lang.Object).
    P.S.
    1) I have transaction attribute set to "Required" for all methods of all beans
    2) I have unique index for each table:
    TMP_GROUP_I1: CAPTION
    TMP_EMPLOYEE_I1: LOGIN (however i think GROUP_ID must be added here too)
    3) I tried many:many relationship with this tables and it works fine
    4) I try another implementation of addEmployee method with
    EmployeeLocal employee = employeeHome.create(login, groupId);
    without using GroupLocal cmr-field and GroupLocalHome findByPrimaryKey method, the result is same error.
    Can somebody help me with this problem?
    Thanks in advance.
    Best regards, Abramov Andrey.

    gimbal2 wrote:
    1: The @JoinColumn on the listOfDepartments collection in Company is wrong. It should be something like this for a bidirectional relationship:
    @OneToMany(mappedBy="company") // company is the matching property name in Department
    private List <Department> listOfDepartment = new ArrayList<Department>();Note that I removed the fetch configuration; onetomany is fetched lazy by design. Saves some clutter eh.
    2: use a Set in stead of a List (hibernate doesn't like lists much in entities and will break when you create slightly more complex entity relations)
    3: don't just slap cascades on collections, especially of type ALL. Do it with care. In the many years I've been using JPA I've only had to cascade deletes in very specific situations, maybe once or twice. I never needed any of the other cascade types, they just invite sloppy code if you ask me. When working with persistence you should apply a little precision.I made all changes as you mentioned but still compID in department table shows null value...

  • Problems with materialized view and fk between two db

    Hi,
    i have two databases db1 and db2 and from db1 is a table(DM_MESSDATEN) which contains a foreign key to a table(DM_FAUNA) in db2.
    Now I want to write my done steps to get more clearification and hopefully someone can point out my wrong steps.
    1st
    i create the tables inside db1 without a foreign key to the table in db2.
    2nd
    i create a database link inside db1 to db2
    create public database link DATENBANK2 connect to phantomas identified by bachelor06 using 'DMDB2';
    3rd
    now and here i stuck want to create a materialized view inside db1
    create materialized view DATAMART_MVW AS
    select * from DM_MESSDATEN, DM_FAUNA@DATENBANK2
    where DM_MESSDATEN.FAUNA_ID=DM_FAUNA.FAUNA_ID;
    or should the view be created inside of db2?
    4th
    and then i want to reactivate the foreign key inside the table of db1- but can't because of
    problems in step 3 :(
    So it would be nice if someone could help me
    thanks a lot
    thomas

    I think you haven't been clear in your statement of your problem:
    now and here i stuck want to create a materialized view inside db1Why are you stuck? If you want to enforce a froeign key locally using data from a remote database then you need to build a materialized view on your local table tablespace that sucks data across from the remote database. You can then create a foreign key on your local table using the local MV.
    If the remote table is updated frequently and you want the local MV kept in sync then you will need to put soem further replication in place. For instance you may need to create a materilaized view log on the remote database.
    Cheers, APC

  • How to give relationship between two tables with comon column with between oprator

    Hi Folks,
    I am using Sql Server 2008R2. I am getting a problem to establish relationship between two tables. 
    I have two Tables, 1.Inventory Details Table another one is Inventory Header Table.
    Inventory Details Table having a column Card No and inventory Header Table having columns  From card No and To Card No.
    I want to give relationship between these two tables with Card no. Could you please provide me the Sql Query.
    Your help would be greatly appreciated .
    Regards
    hasthi.
    email:[email protected]

    Hi Raju,
     We have two way that we can relate to the table either join or quality condition use following syntax/Query  for relating two tables 
    select * from Inventory_Details ID inner join  Inventory_Header IH on ID.CardNo between IH.FrmCardno and IH.ToCardNo
    or 
    Select * from  Inventory_Details ID ,Inventory_Header IH where ID.CardNo=IH.CardNo OrSelect * from  Inventory_Details ID ,Inventory_Header IH where ID.CardNo between IH.FrmCardno and IH.ToCardNo
    Hope this will help you 
    Niraj Sevalkar

  • Additional data on relationship between two objects

    Hi
    We have a requirement to capture additional data on a relationship between two objects.  The data to be captured are custom fields that are unique to the relationship between the objects and not specific to either of the objects.
    We created a new object type and related it to the position (S)and the job (C) object.  In the customising (Personnel Management/Personnel Development/Basic Settings/Maintain Relationships there is an option to set up Additional Data.  There are however several restrictions (e.g. the substructure has to be in T77AD).  When you set up an existing substructure (e.g. PAD22) and screen (e.g. 3000), it works really well, however we have not been able to get this to read our own substructure and screen (since there is no customer include on HRP1001 and the 'Additional data' button seems to go to MP100100 to find the screen).
    My question is two fold:
    a) Is this an allowed customisation (e.g. can we create our own substructure, screen and Query string)? And if so, how does the data get into T77AD (since SAP recommends that data should not be added to this table)? and
    b) Is there any documentation on this (thus far I have only received info on how to enhance infotypes which I don't think is relevant???)?
    If this can not be maintained is there any other suggestions on how to deal with this scenario?
    Any assistance will be appreciated.
    Regards
    Liezl

    Hi everyone
    Thanks for everyone who tried to assist us with this.  I am happy to report that our in-house guru's have found the answer.  So, for anyone who is interested:
    In programme MP100100 you have a screen 6000 which is a customer enhancements screen.  We set up two in-house function modules for the PBO and PAI with its own screen and added an append structure to PAD31 to add the fields required.  In the configuration, we then specified PAD31 as the substructure with screen 6000 and then also specified our own PBO and PAI function modules.  The parameters required for screen 6000 is set up within our own customer screens.
    Hope this will be helpful to someone - it certainly seemed to open up some doors for us!
    Regards
    Liezl

  • How to create relationship between two records using MDM Java APIs

    Hi,
    I am trying to create relationship between two records using Java Apis. Please guide me in doing this.
    Regards,
    Niraj

    Hi Niraj,
    There is ModifyRelationshipsCommand:
    http://help.sap.com/javadocs/MDM/SP06/com/sap/mdm/data/commands/ModifyRelationshipsCommand.html
    Retrieve Relationship command:
    http://help.sap.com/javadocs/MDM/current/com/sap/mdm/schema/commands/GetRelationshipListCommand.html
    Also, please refer similar thread, MDM Java API and relationships.
    Hope it helps..
    Regards,
    Mandeep Saini

  • How to get relationship between two  views in the  reports

    How to get relationship between two  views in the  reports, I am doing a deletion program , it is fully relates to views , how to get relationship between them in the reports

    Hi,
    Please explain your question in detail...what do you want to read ?
    If you want to know about the navigation links between the views then you can use APIs  like
    wdComponentAPI.getComponentInfo().findInWindows("windowName").getViewUsageByID("Name").getNavigationLinks();
    Iterate through the navigationLinkInfo from above collection and can read the other properties .
    I haven't tried the above , but it should work !!!
    Regards,Anilkumar

  • XOR arc among  various relationships between two entities

    I have a scenarious where subtype is implemented as XOR arc among 1:1 relationships between two entities.Not familiar how to make the arc of exclusive or ..in SQL Modeler.
    Grateful for any direction.
    Kind Regards
    Ivan,

    Hi Ivan,
    here are steps for logical model (they are similar for relational model):
    1) select two (or more) relationships and entity they are connected to
    2) Click on "New Arc" icon to create arc
    Philip

  • Create AlE Relationship between two company code F210 to FN21 (UHP To UPI)

    Hi,
    I want to know how to create ALE realtion ship between two company code ( F210 to FN21(Server name UHP to UPI )  and how to process it?
    Please reply ASAP.
    Regards,
    Achin

    Hi Sathish,
    Thanks for reply!..
    But My question I want to Add ALE relationship between two company code F210 to FN21 (UHP(Production server) To UPI(Third Party System)).
    Regards!
    Achin

  • How to build "Greater/less or Equal" relationships between two tables?

    Hi,
    Is there any straightforward approachs to realize the following kind of relationships between two tables?
    Table1.process_end_date >= Table2.work_start_date and
    Table1.process_end_date <= Table2.work_end_date
    BTW, there's no common columns for these two tables to do simple joins (inner, outter...).
    Thanks.
    Regards,
    Qilong 

    Sure.
    Table.SelectRows filters a given table (in this case Table2) based on a function provided as the second argument.
    (table2Row) => is the start of our filter function. It defines a function that takes one argument, called table2Row. Each row of Table2 will be passed to this function. If the function returns true, the row will be kept. If the function returns false,
    the row will be filtered out.
    The right hand side of the => is the filter expression. Because we're adding the custom column to Table1, we can reference a field in the current row of Table1 using square brackets (e.g. [process_end_date]). To reference the fields in the current row
    of Table2, we have to index into the table2Row variable passed to our function (e.g. table2Row[work_start_date]).
    Hope that helps.
    Ehren

  • Relationship between two tables

    Hi,
    Can some one tell me how can i find the relationship between two tables in CRM. is there any transaction for the same. Is it possible to see the data model.
    Thanks
    Akila.R

    Hi Nishant ,
    Could you please explain brief about the Data relationship ......??
    I can see the Foreign Key & Check Table relation in se11 .
    Since I am in the Analysing phase ,
    what are all the details can i get from Foreign Key & Check table kind relations ...??
    Thanks
    Rgds
    Ganesh

  • How to identify the follow up relationship between two service ticket

    Hi Folks,
    How to identify the follow up relationship between two service ticket ?
    Please help me on this...
    Regards,
    Shashi K, Reddy

    Hi Pepe !
    Thank you for the answer, but I dont find this structure ET_DOC_FLOW.....
    Please let me know is that structure is correct ......
    Regards,
    Shashi K, Reddy
    shashikumarreddy at gmail dot com

  • How to create relationShip between two resources??

    Hi,
    Is there any manual process on workbench to create relationShip between two resources like repositoryClient.createRelationship() API does.
    Regards
    Sunil

    Hi Niraj,
    There is ModifyRelationshipsCommand:
    http://help.sap.com/javadocs/MDM/SP06/com/sap/mdm/data/commands/ModifyRelationshipsCommand.html
    Retrieve Relationship command:
    http://help.sap.com/javadocs/MDM/current/com/sap/mdm/schema/commands/GetRelationshipListCommand.html
    Also, please refer similar thread, MDM Java API and relationships.
    Hope it helps..
    Regards,
    Mandeep Saini

  • How exchange messages between two user-bean instances?

    Hi,
    I would like to let several user to log-in my web site (I'm using tomcat) and then let them exchange some messages until they are logged-in. Is there a way using JSF?
    I was thinking about implementing a list of messages inside each user-bean. The user should know that other users are logged-in, that could be listed in a table, and click on its name. I would like that the click action create an item in the list valiable of the selected user. Is that possible using JSF? I didn't find any of such kind of communication between two user-bean instances.
    Do you have any hints? Is that the right way or is there other possibilities?
    Thanks

    You could get hold of a map of sessions in the application scope. Make use of HttpSessionListener to add/remove sessions to/from the map.
    JSF is just another component based MVC framework on top of JSP/Servlet. Everything which you can do in JSP/Servlet is just still possible. You only need to understand how JSF works under the hood.

Maybe you are looking for

  • How do I change my profile in Netflix on the iPad mini

    I Want to change my profile from one of my family members to mine but not the accounts just the profiles. I would love it if someone could please tell me how I can do that on my iPad mini for Netflix.

  • All photos are deleted but phototheque take 3.5 Go Memory !!

    Hi everybody, I deleted all photos, but when I look in usage of phototheque it takes 3.5 Go of memory. Any idea o how to liberate this frozen memory ???? Help needed. thx comiv

  • N95 bluetooth services, and firmware

    Phone: N95 Firmware: 10.0.018 Nokia PC Suite: 6.81.13.0 Problem: - I am trying to use N95 as a bluetooth control for my PC. There is a Java software (Moccatroller) that has server/PC Java application and client/phone applcation. However, I can not es

  • Place my contacts list back to the right hand side of my e mail page

    My contacts list in my e mail ,are no longer on the right hand side and visual when reading my mail. How can I put them back to the old system? PV3-571G OS system Windows 7 home Premium 64 bit.

  • Examples making a REAL store for ebooks?

    Hi, I have ACS4 installed and FINALLY up and running. Adobe support was actually pretty helpful, the user manual was another story. So my question is this...I have the sample store up and running and have been able to upload one of my companies books