Mapping one-to-one relationship

Hi mates, i have two tables
// Car Table CREATE TABLE CAR ( CAR_ID NUMBER(19,0) DEFAULT 1 NOT NULL, LAST_UPDATE TIMESTAMP DEFAULT SYSDATE, MAKE VARCHAR2(20), MODEL NUMBER(5,0), REGISTRATION VARCHAR2(25), MILEAGE NUMBER, ENGINE_SIZE NUMBER(1,1), TANK_SIZE NUMBER(2,0), GAS_IN_TANK NUMBER(2,0), CATEGORY_ID NUMBER(19,0) DEFAULT 1 NOT NULL, PRIMARY KEY (CAR_ID) ); // Contract CREATE TABLE CONTRACT ( CONTRACT_ID NUMBER(19,0) DEFAULT 1 NOT NULL, LAST_UPDATE DATE DEFAULT SYSDATE, STATUS VARCHAR2(32), ORDER_NUMBER VARCHAR2(32), RENTAL_DATE DATE, CUSTOMER_ID NUMBER(19,0) DEFAULT 1 NOT NULL, PRIMARY KEY (CONTRACT_ID) );
I need to establish a one-to-one relationship here (a contract has one car associated to it, car will only belong to one active contract ) .. If i add foreign key to Car and reference Contract
ALTER TABLE CAR ADD FOREIGN KEY (CAR_ID) REFERENCES CONTRACT (CONTRACT_ID) ;
Then use reverse engineering to create hibernate mappings (in eclipse), i get a one-to-many relationship (contract has many cars)? how do i enforce table to to be interpreted this way?

sonx wrote:
(a contract has one car associated to it, car will only belong to one active contract ) The relationship is from contract to car.
.. If i add foreign key to Car and reference Contract
ALTER TABLE CAR
     ADD FOREIGN KEY (CAR_ID)
     REFERENCES CONTRACT (CONTRACT_ID)
;This relationship is from car to contract.
Which contradicts what you said above.
And isn't logical. A car will over time belong to different contracts. Each contract retains the original car. The car can't contain all of them.

Similar Messages

  • Problem with cascade delete in CMP one-to-one relationship

    I am not able to cascade delete for one-to-one relationship. Even though relationship seems to be setup correctly, record from the second table is not deleted.
    Following is the structure of tables i am using:
    First Table(vcc_lrmc) -- LRMCBean
    lrmc_id pk (Bean field is id)
    lrmc_dtl_id (Bean field islrmcDtlId)
    Second Table (vcc_lrmc_dtl) -- LRMCDetailBean
    lrmc_dtl_id (pk) (Bean field islrmcDtlId)
    lrmc_id (Bean field id)
    One to one bidirectional relationship has been setup with CMR fields moreLRMC and mainLRMC.
    section of ejb-jar is as follows:
    <ejb-relation>
    <ejb-relation-name>LRMCMainToDetail</ejb-relation-name>
    <ejb-relationship-role>
    <multiplicity>One</multiplicity>
    <relationship-role-source>
    <ejb-name>LRMC</ejb-name>
    </relationship-role-source>
    <cmr-field>
    <cmr-field-name>moreLRMC</cmr-field-name>
    </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
    <multiplicity>One</multiplicity>
    <cascade-delete/>
    <relationship-role-source>
    <ejb-name>LRMCDetail</ejb-name>
    </relationship-role-source>
    <cmr-field>
    <cmr-field-name>mainLRMC</cmr-field-name>
    </cmr-field>
    </ejb-relationship-role>
    </ejb-relation>
    section of orion-ejb-jar is as follows:(Bidirectional mapping)
    <entity-deployment name="LRMC" data-source="jdbc/VCCDS" table="VCC_LRMC">
    <cmp-field-mapping name="moreLRMC">
    <entity-ref home="LRMCDetail">
    <cmp-field-mapping name="lrmcDtlId" persistence-name="LRMC_DTL_ID"/>
    </entity-ref>
    </cmp-field-mapping>
    </entity-deployment>
    <entity-deployment name="LRMCDetail" data-source="jdbc/VCCDS" table="VCC_LRMC_DTL">
    <cmp-field-mapping name="mainLRMC">
    <entity-ref home="LRMC">
    <cmp-field-mapping name="id" persistence-name="LRMC_ID"/>
    </entity-ref>
    </cmp-field-mapping>
    </entity-deployment>
    Is there anything else need to be setup for Cascade delete or is there anything wrong the way one-to-one relationship has been setup.
    Pls. advice.
    Thanks
    Dhiraj

    Is it happening because of this bug.
    Cannot create a 1:1 bi-directional CMR for entity beans when database tables are reverse engineered. (2447364)
    Anyone, any idea on this ?
    Cheers,
    Dhiraj

  • How to query objects on variable one-to-one relationship

    Hi,
    I have a situation here:
    Application (APPLICATION table) has many payoffs (Payoff table); Primary key of application is the foreign key of payoff.
    Payoff has disbursement, such as check(check table), directDeposit(directDeposit table) or Wire(wire table), which is variable one-to-one relationship. They share the same primary key
    The query I need to run is to search application based on check number, How do I construct a query to perform this kind of search?
    Thanks
    Hao
    [email protected]

    Hi Doug,
    Thanks for all your help. But I guess I still need more details from you to help me understand the solution.
    First of all, I want to make sure I make my case clear
    Application (application table, pk: uniqueAppId) has many payoffs (Payoff table, pk: payoffId);
    Payoff object has variable one-to-one mapping to Disbursement object, which is a abstract super clss for following objects:
    Check(payoff-check table, pk: payoffId)
    DirectDeposit(payoff-deposit table, pk: payoffId)
    Wire(payoff-wire table, pk: payoffId),
    The query I want to run is to get me back an application for a particular check number
    From you email, first I thought "check" is a object, then your sample code showed it is a string. So I am kind of confused. The document you pointed seems not reflect my case. I wonder it is because I didn't present my case clear the first time.
    Looking forward to your further help
    Hao

  • Aggregate with a one-to-one relationship

    Is there a way for mapping a one-to-one relationship between an aggregate and a regular descriptor according to the class the aggregate is aggregated to?
    For example Class A contains Class B as an aggregate. Class B is associated to Class C in a one-to-one relationship. Class A' may also use the same aggregation.
    How to specify the table reference so that it is respectively a Table C to Table A database relationship and a Table C to Table A' relationship.
    I hope this is clear!?
    Please advice,
    Chris

    If I understand you have a shared aggregate B from A and A' that has a 1-1 relationship to C.
    To map this in the Mapping Workbench, first map A, A'. Then map the aggregate B, in mapping its 1-1 to C you should be able to choose any of the foreign keys references in A (or the first descriptor that mapped to the aggregate). You then go into the A and A' aggregate mappings and map the foreign key field in the aggregate to the foreign key field in the source descriptor's table.
    If defining the mappings in code you can choose to map the aggregate to either table, or the commonly named fields. If the field names in the source descriptor's table differ, then you provide a field-name translation in the aggregate mapping.

  • Redefining the one-to-one relationship selection criteria

    In this example, one instance of Contract is related to one instance of Condition.
    Class Contract is associated to table CONTRACT and Class Condition is associated to table CONDITION.
    CONTRACT contains only one field : ID (primary key) CONDITION contains one foreign key field to CONTRACT (CONTRACT_OID), one START_DATE and one END_DATE.
    When loading the contract, I must take one given date (myGivenDate) in consideration so that only the condition including this date (START_DATE <= myGivenDate < END_DATE) is loaded.
    I consider redefining the selection criteria of the one-to-one relationship by adding the criteria on the date. But how to introduce the givenDate parameter?
    Please advice,
    Chris

    Hello Chris,
    I'm sure you might have already seen the discussions on some of the pitfalls of implementing this, but if you haven't, check out:
    Re: 1:M filtering
    I would suggest instead not mapping the Contract -> Condition relationship, and instead query for it when you require the related Condition objects. This query could be hidden inside the Contract objects getCondition method so it is still hiden, and still ensure that what is in the cache reflects the database.
    If this will not an option, then there is a suggestion made by Stephen that maybe what you are looking for in the thread at:
    Associating selection criteria w/One-to-Many (1-M) indirect queries
    Best Regards,
    Chris

  • Many Portal users mapping one R/3 user and query their own data ?

    Hi everyone :
      I want to discuss a issue as follow with all :
      Precondition : The SSO had done between Portal and R/3.
      Issue : Many Portal user(vendor) mapping one R/3 user(pulic vendor user),when they logon Portal, they can query the report, but the data was for the vendor logon now !
      Any discuss is welcome!
      Best Regards,
      Jianguo Chen

    Hi everyone :
      I want to discuss a issue as follow with all :
      Precondition : The SSO had done between Portal and R/3.
      Issue : Many Portal user(vendor) mapping one R/3 user(pulic vendor user),when they logon Portal, they can query the report, but the data was for the vendor logon now !
      Any discuss is welcome!
      Best Regards,
      Jianguo Chen

  • One to one relationship between records while entering in MDM data manager?

    Example Scenario::
         I have created <b>Employee details</b>(main table) and<b> Salary</b> (look up flat table for employee number filed in main table) .  Tried to get the corresponding employee's gross salary from <b>salary</b> table to <b>employee Details</b> table basing on <b>Employee number</b> field in Employee Details table as <b>Gross salary</b> and <b>Employee number</b> are common fields for both the tables. But i could not get one to one relationship in this case , Please explain how to achieve?

    Employee Details (Main Table)
                   EmpNo(Look up field)      EmpNa     GrossSal(Look up field)
    Salary Details  (Look Flat Table)
         Empno         Basic Sal        GrossSal   
          012              5000             10000
                     013              4000               8000
    I have created two tables with the above fields. In main table i kept two look up fields to Salary Details table. First i have entered data to salary table as above , now when i am trying to enter data in to main table EmpNo as 012 it should show Gross salary as 10000 automatically as per the corresponding EmpNo. Instead it is showing all the Grosssal values of Salary table.

  • If Company has one to one relationship with Company code

    Dear All,
    If Company has one to one relationship with company code in the transaction system (ECC),
    can we use company in place off company code - in the BCS system?
    That is, in this case - under consolidation units
    - company,
    i will be using the ECC companies rather than ECC company codes as consolidation units.
    Request your insights.
    Cheers
    Kumar

    Actually, I almost always use the company, not the company code. The difference is in the different number of attributes, and the type CHAR 4 or 6. 0COMPANY is the standard infoobject for using in SEM-BCS.
    Though, I also used the custom infoobject for ConsUnit. Not a problem. Everything works. Just one needs to be careful with infoobjects which are the references to the Company IO.

  • Message mapping: one as many, function node

    hi
    how to use - one as many - function node in mapping. i want to mapping one value from source structure to many fields in target structure. but i dont know the exact functionality of - one as many -
    kindly solve my issue
    regards
    mano

    Hi,
    Check out this example from SAP, which demos the use of the function oneAsMany:
    [http://help.sap.com/saphelp_nw04/helpdata/en/38/85b142fa26c811e10000000a1550b0/frameset.htm]
    Hope this helps,
    Sumant.

  • Mapping one node to many nodes

    How do you map one node in a controller context to many other nodes in another controller context?
    Here's the situation I'd be using this.
    I have an Adaptive RFC model from which I created a Custom Controller. I then used the wizard to map to the model.
    The model corresponds to RFC functions and many of those functions accept the same parameters, LanID for instance. I simply want to have one "LanID" node in a controller that I would set. The change would then propagate to the other LanID context nodes in the Custom Controller mapped to the model.
    What's the best way to handle this?

    If I understand correctly.. B1, B2 and B3 are all in the SAME custom controller?  Even if they are, I don't see a problem of mapping them all to A1 which is in another controller. Let's say that A1 is the "original" node, and B1, B2 and B3 are the "mapped" nodes.
    If you require that B1, B2 and B3 are "original" nodes, and A1 is the "mapped" node, then this is scenario is impossible.
    If you can be more specific, I will try to answer your question better.
    Walter

  • Can Legal Entity - Operating Unit have One to One Relationship in R12

    Hi,
    I want to configure one Legal Entity to one Operating Unit in R12 as it was in 11i. ie One to One Relationship, How can I achieve this ?
    Thanks in Advance,
    Thejas

    That is because you're not setting it, obviously. Nowhere in your code are you actually populating the order property of the orderlines.

  • One to one relationship modelling

    Hi all
    How to model a one to one relationship?
    i have a scenario where i had to maintain 2 different entities and cannot merge them into a single table coz they are separate entities
    Now while modelling them ... do we need to have a primary key for the second table (or)
    use the primary key of the first table as the foreign key on the second table with Unique constraint on it .
    Ex: a single subscription has a single criteria
    subscription table ........... and criteria table
    now should i iuse criteria id as a primary key of criteria table ? (or)
    subscription id as the foregin key in the criteria table ?
    or allow include both in the criteria table
    please suggest
    Thanks and Regards
    Raj

    hi dportas,
    first of all thanks for your respose...
    what is reciprocal foreign key?
    my scenario is like this
    i have a table called subscriptions which records all subscriptions that we have subscribed to to receive an alert to our email primary key is subscriptionid.
    every alert has an alert criteria with different set of attributes
    hence i have 5 alert criteria tables... each with totlally different type of attributes
    eg: balance criteria (balanceamount,condition) cutoff criteria(cutofftime,....)
    we can subscribe to only one alert in a single subscription
    hence subscription to balance criteria table is 1-1
    subscription to cutoff criteria table is 1-1
    now my question is that shoudl each of the criteria table should have criteriaid (or) should i put subscription id as the foregih key in each of the tables for relationship

  • How to generate lookup if there is one-to-one relationship?

    Hi,
    I am an new Jheadstart user and i am using Oracle Developer 10g with Jheadstart.
    There are two tables in my database with a one-to-one relationship between them.
    My database concept is that I need to have one table as a lookup of the other one. Jheadstart does not generate it that way because the relationship is not one-to-many, so I am not geting nor choice, nor lov.
    Could this possibly be solved?

    You probably get better answers in the JHeadstart forum.

  • How to map one modbus register to another modbus register in labview?

    How to map one modbus register to another modbus register in labview? For example, let 40001 equal to 30001. Thank you.
    Steven

    Hello Steven,
    Sorry, I was under the impression that you were using the complete Lookout development software (as opposed to just the Lookout Protocol Drivers). You cannot do any development (connections, mapping, etc.) with the Lookout Protocol Drivers (LPD). So, you were right. We have to do this in LabVIEW.
    I ain't sure how exactly the Modicon floats work, but assuming what you're saying is correct, in your LabVIEW VI(s) you would read the DataSocket item corresponding to 40yyy+1 first, and then write this value back to the DataSocket item corresponding to 40xxx. Similarly, you would read the DataSocket item corresponding to 40yyy and then write the value read back to the DataSocket item corresponding to 40xxx+1.
    A tip: I wou
    ld at first make sure I have the OPC communication between LabVIEW and LPD working. Make sure you can read and write to the LPD registers via their DataSocket/OPC equivalents in LabVIEW. You can then implement the mapping as described above.
    Hope this helps,
    Khalid

  • One to One relationship

    Oracle 11.0.1.7:
    Is it ok to have foreign key as primary key in one to one relationship? Is there any drawbacks? I have 2 options:
    1. Create sequence primary key
    2. Or make foreign key as primary key
    Which one is better and why? I like # 2 just because I don't have to create extra index, sequence and column.

    user628400 wrote:
    Oracle 11.0.1.7:
    Is it ok to have foreign key as primary key in one to one relationship? If the relationship is truely one-to-one, then you haven't properly normalized your data.
    "Every nonkey attribute must be functionally dependent upon
         the key, (1NF)
         the whole key, and (2NF)
         nothing but the key, (3NF)
         so help you Codd."
    Is there any drawbacks? I have 2 options:
    1. Create sequence primary key
    2. Or make foreign key as primary key
    Which one is better and why? I like # 2 just because I don't have to create extra index, sequence and column.

Maybe you are looking for

  • HT1277 how can i remove the email add from a deleted mailbox from the prompts of the 'from' field?

    how can i remove the email add from a deleted mailbox from the prompts of the 'from' field?

  • Time capsule produces a signal, but won't connect or backup

    I have looked at some of the other discussions here; some are similar, but I can't find an answer. I have a TC, Macbook Pro and an iPhone 4, all between 6-10 months old.   My problems started when I turned on all my stuff after being away for 4 weeks

  • Why can't I delete or open a PSD jpeg saved for Web from my desktop?

    I was working with photoshop today and saved multiple versions of the same flyer I made to my desktop. One of the flyer versions I clicked "save for web" and it showed up as a jpeg on my desktop. I cleaned up my desktop today and I can't put that ver

  • Key not available

    I have a use case where I have a child table with a foreign key from the master table, and the key is being generated from a sequence. And I have to insert data into the child table ,before I insert in the master table.So how do I insert the foreign

  • IBooks Author headline language

    I'm working on a product manual that my colleague started. This product manual has to be in English. My colleague has set his system language to Norwegian while mine is English, so all headlines, paragraph styles and content in the TOC is in Norwegia