Many to One in Triggers

Hello,
I am writing a Trigger that needs to perform the following , if there is any change in any of columns of Table A I need to propagate the same to Table B . By changes I mean insert(s)/update(s) or delete(s).
if table A has one row representing say Column1 which is an integer then it is a clear & simple copy of values .
However if table A has multiple rows having the same Column1 I need to choose the minimum of the values in Column1 & whichever column has the minimum value need to put it in Table B . Let us assume Column1 is of Integer type .
Would appreciate any suggestions regarding teh same
With Regards

The Second table basically resides in another schema , the whole idea is to make sure the second table has the same data as the first one , I don't want to get rid of the first table as it is still being used by old applications but I need a new table for the newer app's that don't need as much details as the older app's but need a representative row (atleast one column for Column1 values) .

Similar Messages

  • Crystal Report Many to One Query Config error when using DataSet.ReadXML me

    When I build a dataset with this method numerous relations are automatically created. I then map these fields onto crystal reports with ADO.net data connection. However when I run the report the following error occurs:
    CrystalDecisions.CrystalReports.Engine.InternalException: Cannot determine the queries necessary to get data for this report.Details:
    This query cannot be performed. The link order requires many to one query configuration, which is not supported. Please rearrange the links.
    If I remove the links (relations) i get duplicate data on the report. Is there any way to resolve this or a patch for the error?

    Hello, Mervin;
    Since you are using ADO.NET dataset, is it possible to get all of the fields you need in one SQL Query outside of Crystal Reports?
    If that is possible, you can use that dataset to create an XML or XSD file to use as the structure for your report.
    VB
    'Using the full path to the .xml file, include the schema
    dataSet.WriteXml("C:\temp\test.xml", XmlWriteMode.WriteSchema)
    or
    dataSet.WriteXmlSchema("c:\temp\testXML.xsd")
    Now create a new report with the ADO.NET(XML) connection and point to either the XML or XSD you created. XML is useful because you can view data in the report designer for final formatting of the report.
    Now there is only one datasource and no linking is required in Crystal Reports. That should resolve the one to many issue.
    Another useful tool is to group on the many and place all the fields normally in the detail section into that group header. Suppress the Detail and Group footer sections. The Group Header will now look like a Detail section and each distinct value will only appear once. You can group on one field or a combination (using a formula field) to get the results you need. Test this to be sure you do not miss anything you want to see.
    Elaine

  • Does anyone know how many devices one can have on one apple ID?

    Does anyone know how many devices one can have on one apple ID?

    The names are for your benefit. The devices are identified by serial number in iTunes. iTunes knows which device is which no matter what you name the devices. It works the same way with iCloud. You can name all three devices Fred - and iTunes can tell them apart - but like I said, you want to give them different names for your benefit.

  • Many to One Mapping issue

    Hi Experts,
    I am currently facing issue with many to one mapping . I have a source schema called revenue having Profit and Profit GST which is looping multiple times. I need to copy the name,value and GST value for each type into the destination schema.
    i am using Looping funtiod to create item profit records and than copying name and value from source to destination but the problem statement is that i am unable to map the GST value
    Thanks
    Abhishek

    could you post the schema definition please
    well why i am asking is, in General matching the records will be based on common node values in corresponding records.
    Assume you have 2 records of Profit and 2 records of ProfitGST in the source message like below, you cannot match the records unless you have some value common in both the records. i mean there should be some common node or attribute value that exits in
    both records.
    assume the following sample with 2 records each
    <ns0:Revenue xmlns:ns0="http://TestSample">
    <ns0:profit availabilityIncentivePayment="342" increasedCapacityCharge ="121" increasedCapacaityPayment="231" />
    <ns0:profit availabilityIncentivePayment="100" increasedCapacityCharge ="110" increasedCapacaityPayment="120" />
    <ns0:profitGST availabilityIncentivePayment="55" increasedCapacityCharge ="21" increasedCapacaityPayment="23"/>
    <ns0:profitGST availabilityIncentivePayment="150" increasedCapacityCharge ="160" increasedCapacaityPayment="170"/>
    </ns0:Revenue>
    if you observe the above sample instance, it does have 2 records each, but Profit record's nodes values
    are no where common with ProftGST record's node values.
    And for every Profit record, you want to pick corresponding GST value from ProfitGST record. However, since you don't have atleast one common node/attribute value here, you will not find a way to relate corresponding records. Means while mapping the first
    record of Profit, it cannot decide which record's nodes values in the ProftGST should pick to match as there are 2 records of ProfitGSt and with no relation with Profit Records.
    if the requirement is such that the records should be matched by the order(index) irrespective
    or the values in them, then that can be achieved easily with postion() function in the for loop.  just try to use code some thing like below sample xslt script like below, apply the proper name spaces and put full names as applicable in your scirpt, mould
    it as per your need
    <ns0:Root>
    <xsl:for-each select="Profit">
    <Profit>
    <xsl:if test="@availabilityIncentivePayment">
    <name>
    name>availabilityIncentivePayment</name>
    </name>
    </xsl:if>
    <xsl:if test="@increasedCapacityCharge">
    <Value>
    <xsl:value-of select="@increasedCapacityCharge" />
    </Value>
    </xsl:if>
    <xsl:if test="../profitGST/@availabilityIncentivePayment">
    <ProfitGSt>
    <xsl:value-of select="../profitGST/@availabilityIncentivePayment[position()]" />
    </ProfitGSt>
    </xsl:if>
    </Profit>
    </xsl:for-each>
    </ns0:Root>
    Please mark the post as answer if this answers your question. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • SSAS - Many to Many Relationship Grain Filters Out Data (Many to One)

    I have a simple Many to One example: One Fact Table record has many Dimensional Items.  The Example I'm using is One FactEvent record can have multiple EventMembers.  These members are always unique so the relationship is really many to one (vs.
    many to many). The grain of the Fact is one row for every event.  Not all events have members, but I have stubbed those with -1
    I tried using a Referenced dimensional relationship, but it threw my total counts off.  I decided to make it more complicated by using a
    Many to Many relationship, but I had issues once I started slicing the data.
    The following are my two very simple tables:
    FactEvents:
    EventMemberID MemberKey EventMemberKey MemberName MemberGender
    1             1         -1             None       N          
    2             2         E2             Tyler      M          
    3             3         E2             John       M          
    4             4         E2             Sue        F          
    5             5         E5             Tim        M          
    6             6         E5             Jane       F          
    7             7         E12            Ashley     F          
    8             8         E12            Jessica    F          
    9             9         E12            Kristy     F          
    10            10        E17            Mike       M          
    11            11        E17            Josh       M          
    12            12        E18            Warren     M          
    13            13        E18            Eric       M           
    Here is the bridge Table:
    EventID EventBK EventName         EventMemberKey EventCount
    1       E1      Hockey Game       -1             1          
    2       E2      Soccer Game       E2             1          
    3       E3      Baseball Game     -1             1          
    4       E4      Concert           -1             1        
    5       E5      Food Festival     E5             1          
    6       E6      Movie Night       -1             1          
    7       E7      Data Group Event  -1             1          
    8       E8      City Tour         -1             1          
    9       E9      Ski Trip          -1             1        
    10      E10     Camping Trip      -1             1          
    11      E11     Hiking Trip       -1             1          
    12      E12     Community Cleanup E12            1          
    13      E13     Block Party       -1             1          
    14      E14     Toastmasters      -1             1          
    15      E15     Train Spotting    -1             1          
    16      E16     Plane Spotting    -1             1          
    17      E17     Fishing Trip      E17            1          
    18      E18     Hunting Trip      E18            1          
    19      E19     Street Hockey     -1             1          
    20      E20     Bonspiel          -1             1          
    You can see many events have no members and some events have multiple members.  There is not separate members Dim, just the bridge table.  I tried to build view that would work as bridge tables, but it started to feel like overkill.
    Here is the SSAS structure:
    Cube:
    I tried creating a bridge Dim and Measure Group that can be used to join FactEvents with DimMemberEvent:
    When I query the database tables directly, I can get the structure I'm looking for:
    Gender  Count
    F            5
    M           7
    N           15
    This represents that although there are 20 events, there were 5 Female and 7 Male participants and 15 events with No participants.  When looking at the cube in excel I get:
    Gender  Count
    F            3
    M           4
    N           15
    Grand Total 20
    The grand total is correct, however, it looks like it is grouping the events, so if there are multiple Female members at a particular event, they get rolled up.  You can see this better if I pull in member name:
    It includes all the names with count 1 ie. 5 Females with count 1, but the gender subtotal is 3 (as it is grouping the gender dimension)
    The detail member counts are good, but the rolled up M and F counts are stripping out duplicates.  Is there a way to model this in SSAS to preserve the detail member counts when the member dimension is used?  Is a many to many the best solution?
    This is all using SQL Server 2012 Multi-Dimensional Model. Thanks.

    Ok, for starters, if it's a one to many relationship, don't set it up as a many to many!  Avoid many to many relationships and really anything other than "regular" relationships. 
    Second, the tables you pasted the data for aren't the tables you are describing them as, based on the dsv screenshot you included.  If your post is confusing to the people who are wanting to help you, they will quickly move on.
    It seems that you are not clear on how to construct a star schema.  I will lay one out for you and hopefully this can help you on your journey.
    fact_member_event:
    event_id
    member_id
    member_event_count
    dim_member:
    member_id
    member_key
    member_name
    member_gender
    dim_event:
    event_id
    event_name
    fact_event:
    event_id
    event_count
    Or alternately, you could drop the fact_event fact table and have a calculated member that uses dimEvent.event.event.allmembers.count.  It's a little bit of a weird situation that I would want to play with, but I would start with the above.  
    Also if you post back and show query results, you should make it clear what columns  you are displaying.  I see "count" in your query above, but nowhere in the star schema do I see "member count"
    as a field.. I guess that's event count?
    Hope this helps,
    Ken

  • XQuery many to one in an XML document ??

    I have XMLType tables with xml documents that have data like the sample below.
    There are one to many InvoiceLineRet to one InvoiceRet, how do I return this data in an XQuery?
    I have tried many iterations but cannot get data to return correctly. It is somewhat like a many to one table relation where in the query the one side would repeat across the many lines, but it does not work that way with XQuery.
    Any and all suggestions will be appreciated.
    Thanks,
    Mike
    sample data:
    <InvoiceRet>
    <TxnID>D924-1210085400</TxnID>
    <TimeCreated>2008-05-06T10:50:00-05:00</TimeCreated>
    <TimeModified>2008-07-21T10:54:42-05:00</TimeModified>
    <EditSequence>1215638595</EditSequence>
    <TxnNumber>10398</TxnNumber>
    <CustomerRef>
    <ListID>80000278-1209483158</ListID>
    <FullName>Majestic Entries</FullName>
    </CustomerRef>
    <ARAccountRef>
    <ListID>80000009-1185470478</ListID>
    <FullName>Accounts Receivable</FullName>
    </ARAccountRef>
    <TemplateRef>
    <ListID>80000019-1190228214</ListID>
    <FullName>Compudoc</FullName>
    </TemplateRef>
    <TxnDate>2008-05-06</TxnDate>
    <RefNumber>22333</RefNumber>
    <BillAddress>
    <Addr1>Majetic Entries</Addr1>
    </BillAddress>
    <BillAddressBlock>
    <Addr1>Majetic Entries</Addr1>
    </BillAddressBlock>
    <IsPending>false</IsPending>
    <IsFinanceCharge>false</IsFinanceCharge>
    <DueDate>2008-05-06</DueDate>
    <ShipDate>2008-05-06</ShipDate>
    <Subtotal>391.50</Subtotal>
    <ItemSalesTaxRef>
    <ListID>8000004F-1185996977</ListID>
    <FullName>NC 7.25%</FullName>
    </ItemSalesTaxRef>
    <SalesTaxPercentage>7.25</SalesTaxPercentage>
    <SalesTaxTotal>5.73</SalesTaxTotal>
    <AppliedAmount>-397.23</AppliedAmount>
    <BalanceRemaining>0.00</BalanceRemaining>
    <IsPaid>true</IsPaid>
    <IsToBePrinted>false</IsToBePrinted>
    <IsToBeEmailed>false</IsToBeEmailed>
    <CustomerSalesTaxCodeRef>
    <ListID>80000001-1185469345</ListID>
    <FullName>Tax</FullName>
    </CustomerSalesTaxCodeRef>
    <InvoiceLineRet>
    <TxnLineID>D926-1210085400</TxnLineID>
    <ItemRef>
    <ListID>80000059-1199714336</ListID>
    <FullName>Labor:Non-Contract Labor Ken</FullName>
    </ItemRef>
    <Desc>Technical Labor performed by Ken Allen:
    Network Problem with Internet and intranet found two routers connected together and the one set for DHCP was bad we changed out their bad one with our small netgear router.</Desc>
    <Quantity>1.5</Quantity>
    <Rate>125.00</Rate>
    <ClassRef>
    <ListID>8000000D-1200208143</ListID>
    <FullName>KA</FullName>
    </ClassRef>
    <Amount>187.50</Amount>
    <ServiceDate>2008-04-28</ServiceDate>
    <SalesTaxCodeRef>
    <ListID>80000002-1185469345</ListID>
    <FullName>Non</FullName>
    </SalesTaxCodeRef>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>D927-1210085400</TxnLineID>
    <ItemRef>
    <ListID>80000029-1185470511</ListID>
    <FullName>Labor:Non-Contract Labor Rick</FullName>
    </ItemRef>
    <Desc>Technical Labor performed by Rick Wagoner: Assisted with above troubleshooting</Desc>
    <Quantity>1</Quantity>
    <Rate>125.00</Rate>
    <ClassRef>
    <ListID>80000004-1185998300</ListID>
    <FullName>RW</FullName>
    </ClassRef>
    <Amount>125.00</Amount>
    <ServiceDate>2008-04-28</ServiceDate>
    <SalesTaxCodeRef>
    <ListID>80000002-1185469345</ListID>
    <FullName>Non</FullName>
    </SalesTaxCodeRef>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>D928-1210085400</TxnLineID>
    <ItemRef>
    <ListID>80000050-1185997340</ListID>
    <FullName>Parts and Supplies</FullName>
    </ItemRef>
    <Desc>Parts and Supplies: Netgear router</Desc>
    <Quantity>1</Quantity>
    <Rate>79.00</Rate>
    <ClassRef>
    <ListID>80000007-1186694551</ListID>
    <FullName>Parts</FullName>
    </ClassRef>
    <Amount>79.00</Amount>
    <SalesTaxCodeRef>
    <ListID>80000001-1185469345</ListID>
    <FullName>Tax</FullName>
    </SalesTaxCodeRef>
    </InvoiceLineRet>
    </InvoiceRet>
    <InvoiceRet>
    <TxnID>ED59-1216758177</TxnID>
    <TimeCreated>2008-07-22T16:22:57-05:00</TimeCreated>
    <TimeModified>2008-07-26T11:21:48-05:00</TimeModified>
    <EditSequence>1217085708</EditSequence>
    <TxnNumber>11203</TxnNumber>
    <CustomerRef>
    <ListID>80000278-1209483158</ListID>
    <FullName>Majestic Entries</FullName>
    </CustomerRef>
    <ARAccountRef>
    <ListID>80000009-1185470478</ListID>
    <FullName>Accounts Receivable</FullName>
    </ARAccountRef>
    <TemplateRef>
    <ListID>80000019-1190228214</ListID>
    <FullName>Compudoc</FullName>
    </TemplateRef>
    <TxnDate>2008-07-22</TxnDate>
    <RefNumber>22479</RefNumber>
    <BillAddress>
    <Addr1>Majetic Entries</Addr1>
    </BillAddress>
    <BillAddressBlock>
    <Addr1>Majetic Entries</Addr1>
    </BillAddressBlock>
    <IsPending>false</IsPending>
    <IsFinanceCharge>false</IsFinanceCharge>
    <DueDate>2008-07-22</DueDate>
    <ShipDate>2008-07-22</ShipDate>
    <Subtotal>839.00</Subtotal>
    <ItemSalesTaxRef>
    <ListID>8000004F-1185996977</ListID>
    <FullName>NC 7.25%</FullName>
    </ItemSalesTaxRef>
    <SalesTaxPercentage>7.25</SalesTaxPercentage>
    <SalesTaxTotal>33.64</SalesTaxTotal>
    <AppliedAmount>0.00</AppliedAmount>
    <BalanceRemaining>872.64</BalanceRemaining>
    <IsPaid>false</IsPaid>
    <IsToBePrinted>true</IsToBePrinted>
    <IsToBeEmailed>false</IsToBeEmailed>
    <CustomerSalesTaxCodeRef>
    <ListID>80000001-1185469345</ListID>
    <FullName>Tax</FullName>
    </CustomerSalesTaxCodeRef>
    <InvoiceLineRet>
    <TxnLineID>ED5B-1216758177</TxnLineID>
    <ItemRef>
    <ListID>80000050-1185997340</ListID>
    <FullName>Parts and Supplies</FullName>
    </ItemRef>
    <Desc>Parts and Supplies - Linksys Router</Desc>
    <Quantity>1</Quantity>
    <Rate>89.00</Rate>
    <Amount>89.00</Amount>
    <SalesTaxCodeRef>
    <ListID>80000001-1185469345</ListID>
    <FullName>Tax</FullName>
    </SalesTaxCodeRef>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED5C-1216758177</TxnLineID>
    <Desc>Suspect that the phone switch is attempting to act as a DHCP server for the network. per Terry, the reason that the phone switch was on the network was to supply VOIP to the warehouse phone lines. This was not working and is no longer needed. We removed the connection between the phone switch and the network.</Desc>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED5D-1216758177</TxnLineID>
    <Desc>Removed the Netgear router and the D-Link router. The D-Link had lost all settings and we could not log into the Netgear even after resetting to factory defaults.</Desc>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED5E-1216758177</TxnLineID>
    <Desc>Installed a new Lnksys router to replace the D-Link and Netgear faulty routers.</Desc>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED5F-1216758177</TxnLineID>
    <Desc>Ensured that all computers were connecting properly. Ensured that all computers printed to the Savin printer correctly.</Desc>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED60-1216758177</TxnLineID>
    <Desc>Worked with Time Warner Cable to resolve customer location and static IP.</Desc>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED64-1216758177</TxnLineID>
    <ItemRef>
    <ListID>80000028-1185470511</ListID>
    <FullName>Labor:Non-Contract Labor Kareem</FullName>
    </ItemRef>
    <Desc>Analyzed and resolved Internet connectivity problems after loss of service from Time Warner Cable.</Desc>
    <Quantity>3</Quantity>
    <Rate>125.00</Rate>
    <Amount>375.00</Amount>
    <ServiceDate>2008-07-22</ServiceDate>
    <SalesTaxCodeRef>
    <ListID>80000002-1185469345</ListID>
    <FullName>Non</FullName>
    </SalesTaxCodeRef>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED68-1216758177</TxnLineID>
    <ItemRef>
    <ListID>8000005D-1216758445</ListID>
    <FullName>Labor:Non-Contract Labor Mike</FullName>
    </ItemRef>
    <Desc>Analyzed and resolved Internet connectivity problems after loss of service from Time Warner Cable.</Desc>
    <Quantity>3</Quantity>
    <Rate>125.00</Rate>
    <Amount>375.00</Amount>
    <ServiceDate>2008-07-22</ServiceDate>
    <SalesTaxCodeRef>
    <ListID>80000001-1185469345</ListID>
    <FullName>Tax</FullName>
    </SalesTaxCodeRef>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED94-1216758177</TxnLineID>
    <Desc>Terry called, cannot connect to internet. Everyone but Terry can connect. Terry is getting a 172 IP address on his laptop. Walked him through putting a static IP on his laptop so that he could be functional. I went to their site and talked with the NEC phone switch management company. They said the switch does not have DHCP capabilities. I could not duplicate Terry's issue using my laptop. The phone switch is now totally disconnected from the network since the VOIP setup for the warehouse was not functional. Validated that the TWC modem is not DHCP.</Desc>
    <ServiceDate>2008-07-23</ServiceDate>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>ED95-1216758177</TxnLineID>
    <Desc>Requires further diagnostics on Friday the 25th (if Terry is available) - need his laptop on-site to diagnose the problem.</Desc>
    </InvoiceLineRet>
    <InvoiceLineRet>
    <TxnLineID>EE30-1216758177</TxnLineID>
    <Desc>Communicated with Terry on 7/24/2008 via email. He is using DHCP and connecting correctly. Removing the final connection from the phone switch to the network appears to have corrected the problem.</Desc>
    <ServiceDate>2008-07-24</ServiceDate>
    </InvoiceLineRet>
    </InvoiceRet>

    try to use "xmlTable"
    search on this forum u can find much more stuff

  • I i want to run many-to-one replication scenario

    Hi,
    i want to run many-to-one replication scenario and for that i have created two tables and inserted values on source db and one table on target db in which i want consolidated data from those two tables. Below are the table details,
    Source DB,
    CREATE TABLE GGS.CLIENT_INFO
    ( CLIENT_ID varchar2(10) not null,
    CLIENT_NAME varchar2(50) not null,
    CLIENT_ADD varchar2(50),
    CONSTRAINT CLIENTID_PK PRIMARY KEY (CLIENT_ID)
    CREATE TABLE GGS.ACCOUNT_INFO
    ( ACCOUNT_NO varchar2(15) not null,
    BANK_NAME varchar2(50) not null,
    CLIENT_ID varchar2(10) not null,
    CONSTRAINT ACCTNO_PK PRIMARY KEY (ACCOUNT_NO)
    alter table GGS.ACCOUNT_INFO add CONSTRAINT FK_CLIENTINFO FOREIGN KEY (CLIENT_ID) REFERENCES GGS.CLIENT_INFO(CLIENT_ID);
    Target DB,
    CREATE TABLE GGS1.CLIENT_ACCOUNT_INFO
    ( CLIENT_ID varchar2(10) not null,
    ACCOUNT_NO varchar2(15) not null,
    CLIENT_NAME varchar2(50) not null,
    CLIENT_ADD varchar2(50),
    BANK_NAME varchar2(50) not null,
    CONSTRAINT CLIENT_ACCOUNT_PK PRIMARY KEY (CLIENT_ID, ACCOUNT_NO)
    when i start replicat process, it is giving below error,
    *"Oracle GoldenGate Delivery for Oracle, CLACTDEL.prm: OCI Error ORA-01400: cannot insert NULL into ("GGS1"."CLIENT_ACCOUNT_INFO"."CLIENT_NAME") (status = 1400), SQL <INSERT INTO "GGS1"."CLIENT_ACCOUNT_INFO" ("CLIENT_ID","ACCOUNT_NO") VALUES (:a0,:a1)>."*
    Note: i am inserting two source tables data in one table which at target side using OGG capture-replicate process.
    Please help to resolve above error.
    Regards,
    Shital

    For one, do not use the GoldenGate database user as your source and target schema owner. Why? What happens in a bidirectional setup? To prevent ping-ponging of data, operations performed by the replicat user should be ignored. That's what keeps the applied update on a target being re-applied on the original source, and then being captured and sent to the target, etc.
    Without knowing your setup, what did you do for ADD TRANDATA and supplemental logging at the database level (only needed for the source)? What did you do for initial load and synchronization? What are your parameter files?
    The error shown so far - cannot insert null - applies everywhere in Oracle whenever you try to insert a record with a null value in a column where a NOT NULL constraint is present. You can see that for yourself in a SQL*Plus session and trying the insert. You are inserting two column values, when your own table definition shows you would need at least 4 values (to account for all of the not null constraints).

  • HT3819 Isn't the five computer limit for home sharing restrictive given the many devices one household may have?

    Isn't the five computer limit for home sharing restrictive given the many devices one household may have?

    It is only restrictive if you have more than 5 computers.
    Otherwise it is not restrictive at all.
    devices do not count, only computers.
    You have more than 5 computers on the same home network.

  • Many-to-one relationships

    I'm trying to implement a many-to-one relationship similar to the one, for example, between an OrderLineItem and a Product.
    I managed to create the beans and define the relationship using deploytool.
    What I'm trying to understand is how can I prevent a Product instance from being deleted when it is involved in the relationship described above?
    Currently, under Sun's reference implementation server, I am allowed to delete a Product even if there are OrderLineItems that reference it.
    There is one line printed out in the window running j2ee -verbose:
    com.sun.ejb.containers.EntityContainer$EJBTxKey
    The record in the Product table is deleted nonetheless.
    Another weird thing is that the server does not allow me to deploy two beans involved in a many-to-one relationships with the Product bean if they are using the same CMR field name. What I get is a compilation error at the deployment time.
    I'd appreciate any input.

    They way I handle this is to hide the creation/manipulation/deletion of the bean behind a manager - for example a singleton session bean. I NEVER allow the direct creation/deletion of entity beans except through manager classes. This is quite a common J2EE pattern, whose name escapes me at the moment.
    Your manager would have a method like delete(int productId), which would delete the matching Product entity bean, and would then search the OrderLineItem beans for the matching Product primary key.

  • Example: One to many & Many to One..

    Hi All,
    Can anyone send me a sample example for Hibernate One to many & Many to One..
    Also, if there are any links, from where i can download the example, please point me to that..
    Thanks a lot,
    Shridhar..

    http://hibernate.org/5.html#A2
    %

  • "Illegal many to one link" error

    Hi,<br /><br />I&#39;m using JRC to integrate Crystal reports into a web application. When I&#39;m trying to change the database connection info at runtime, the &#39;Illegal many to one link&#39; error is shown. I&#39;ve tried to search for description of that error, but found no solution. The preview in Report Designer works fine.<br />Could you suggest anything?<br />I&#39;m using Crystal Reports XI (Developer)<br /><br />Thanks.<br />

    I am also getting this error using a jdbc connection to an Oracle 9i database. I am creating reports against a test database which has the same schema as the production database.  Due to configuration issues, I do not have access to our production database from my Crystal Reports Design envirionment so I need this code to work to retrieve produciton data when running through the JRC on our production system.
    Any help would be appreciated.

  • One to many and many to one transformation

    I want to transform a field one to many form and many to one.
    EXP: One to MAny
    Name and Address.
    Tanvir Ahmad Mughal
    i want to transfor it as first name=tanvir, M_name=Ahmad, Last name=Mughal
    similer with address. So tell me how i will do in oracle warehouse builder 10G.
    exp: many to one
    the address is stored in 4 attributes in source and i want to store in one field or 2 fields in oracle
    warehouse builder. tell me about it.
    i shall be thankful to you for this kind

    Hi
    Use expressions!
    Select an expression and connect the sorce fiedl to it. Create 3 output filed and define the expressions for them:
    - substr( source_field, 1, instr(source_field, ' '))
    - substr( source_field, instr(source_field, ' '), instr(source_field, ' ', 2))
    - substr( source_field, instr(source_field, ' ', 2)).
    For many to one concatenate them in an expression. Create an expression, connect the source fileds, create an output filed and in the expression use this:
    - field1 || ' ' || field2 || ' ' || field3 || ' ' || field4.
    Ott Karesz
    http://www.trendo-kft.hu

  • Many to one relationships strange behavior

    I have a problem with two many to one relationships.
    The problem appears from the dirty mechanism of cmr/cmp fields.
    When I have two “many-to-one” relationships ex:
    A n..1 B
    A n..1 C
    Navigability: B -> A
              A <-> C
    When I put in ejb-jar.xml the B to A relation first, the bugs appear. The dirty mechanism work chaotic. The problem is in the generated code for the PersistenceManager and Wrapper of the A bean.
    In the Wrapper the only fields with dirty mecansim are the real fields from bean which are navigable. In the PersistenceManager class are the same fields like in the BeanWrapper plus the fake fields for relationship. But the fake fields are intercalated with real fields and the dirty flag values are not the same with the dirty flags from BeanWrapper. Result: chaotic updates.
    Solution(workaround – not elegant): put first the relation which has navigability from A to C and second A to B.

    They way I handle this is to hide the creation/manipulation/deletion of the bean behind a manager - for example a singleton session bean. I NEVER allow the direct creation/deletion of entity beans except through manager classes. This is quite a common J2EE pattern, whose name escapes me at the moment.
    Your manager would have a method like delete(int productId), which would delete the matching Product entity bean, and would then search the OrderLineItem beans for the matching Product primary key.

  • I have had TOPLINK-28018  error afte I had added one-to-many or many-to-one

    Hello.
    I am using TopLink and Spring. I have the followng persistence.xml:
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="registry" transaction-type="RESOURCE_LOCAL">
    <mapping-file>ru/lanit/ps/registry/model/rpaymenttype.xml</mapping-file>
    <mapping-file>ru/lanit/ps/registry/model/radministrativelevel.xml</mapping-file>
    <mapping-file>ru/lanit/ps/registry/model/rterritory.xml</mapping-file>
    <mapping-file>ru/lanit/ps/registry/model/stateowner.xml</mapping-file>
    <properties>
    <property name="com.intellij.javaee.persistence.datasource" value="Datasource"/>
    <property name="toplink.logging.level" value="FINE"/>
    <property name="toplink.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
    <property name="toplink.jdbc.url" value="jdbc:hsqldb:mem:PUBSER"/>
    <property name="toplink.jdbc.password" value=""/>
    <property name="toplink.jdbc.user" value="sa"/>
    </properties>
    </persistence-unit>
    </persistence>
    All my classes are inherited from StateOwner.class and only the RTerritory class has "one-to-many" and "many-to-one" relationships. When I add rterritory.xml to persistence.xml I have the following error (before all works fine):
    log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
    log4j:WARN Please initialize the log4j system properly.
    [TopLink Config]: 2007.12.18 02:47:15.812--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.Long ru.lanit.ps.registry.model.StateOwner.getId()] is being defaulted to: ID.
    [TopLink Config]: 2007.12.18 02:47:15.859--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.Long ru.lanit.ps.registry.model.StateOwner.getStateTerritoryId()] is being defaulted to: STATETERRITORYID.
    [TopLink Config]: 2007.12.18 02:47:15.875--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.String ru.lanit.ps.registry.model.StateOwner.getStringId()] is being defaulted to: STRINGID.
    [TopLink Config]: 2007.12.18 02:47:15.875--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.String ru.lanit.ps.registry.model.StateOwner.getStateStatus()] is being defaulted to: STATESTATUS.
    [TopLink Config]: 2007.12.18 02:47:15.875--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.Long ru.lanit.ps.registry.model.StateOwner.getStateVersion()] is being defaulted to: STATEVERSION.
    [TopLink Config]: 2007.12.18 02:47:15.890--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.String ru.lanit.ps.registry.model.StateOwner.getStateAuthor()] is being defaulted to: STATEAUTHOR.
    [TopLink Config]: 2007.12.18 02:47:15.890--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.sql.Timestamp ru.lanit.ps.registry.model.StateOwner.getStateCreationDate()] is being defaulted to: STATECREATIONDATE.
    [TopLink Config]: 2007.12.18 02:47:15.890--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.sql.Timestamp ru.lanit.ps.registry.model.StateOwner.getStateModificationDate()] is being defaulted to: STATEMODIFICATIONDATE.
    [TopLink Config]: 2007.12.18 02:47:15.890--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.lang.String ru.lanit.ps.registry.model.StateOwner.getStateComment()] is being defaulted to: STATECOMMENT.
    [TopLink Config]: 2007.12.18 02:47:15.906--ServerSession(25709120)--Thread(Thread[main,5,main])--The column name for element [public java.sql.Timestamp ru.lanit.ps.registry.model.StateOwner.getStateProcessedDate()] is being defaulted to: STATEPROCESSEDDATE.
    [TopLink Config]: 2007.12.18 02:47:15.906--ServerSession(25709120)--Thread(Thread[main,5,main])--The discriminator column name for the root inheritance class [class ru.lanit.ps.registry.model.StateOwner] is being defaulted to: DTYPE.
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GroundOfRefusalServiceTarget' defined in class path resource [groundofrefusal.xml]: Cannot resolve reference to bean 'GroundOfRefusalDao' while setting bean property 'dao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GroundOfRefusalDao' defined in class path resource [groundofrefusal.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [openJPAsettings.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [registry] failed.
    Internal Exception: java.lang.NullPointerException
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'GroundOfRefusalDao' defined in class path resource [groundofrefusal.xml]: Cannot resolve reference to bean 'entityManagerFactory' while setting bean property 'entityManagerFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [openJPAsettings.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [registry] failed.
    Internal Exception: java.lang.NullPointerException
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [openJPAsettings.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [registry] failed.
    Internal Exception: java.lang.NullPointerException
    Caused by: javax.persistence.PersistenceException: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [registry] failed.
    Internal Exception: java.lang.NullPointerException
         at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:615)
         at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:178)
         at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:218)
         at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
         at ru.lanit.ps.registry.VerifyApplicationContext.setUp(VerifyApplicationContext.java:44)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
         at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
         at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
         at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
         at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
         at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
         at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
         at com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:78)
         at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
    Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [registry] failed.
    Internal Exception: java.lang.NullPointerException
         at oracle.toplink.essentials.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:212)
         ... 61 more
    Caused by: java.lang.NullPointerException
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.OneToManyAccessor.process(OneToManyAccessor.java:142)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.processRelationship(RelationshipAccessor.java:275)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.processRelationshipDescriptors(MetadataProject.java:564)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.process(MetadataProject.java:497)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processAnnotations(MetadataProcessor.java:231)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:354)
         at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:584)
         ... 60 more
    Process finished with exit code -1
    This is my RTerritory.class and rterritory.xml
    public class RTerritory extends StateOwner {
    private static final long serialVersionUID = 5372570539234097349L;
    //link to parent
    private RTerritory parentTerritory;
    //title
    private String title;
    //string type
    private String type;
    //Level
    private Integer level;
    //set of children
    private Set<RTerritory> children = new HashSet<RTerritory>(0);
    public RTerritory() {
    public RTerritory(Long RTerritory, String title, String type) {
    setId(RTerritory);
    this.title = title;
    this.type = type;
    public RTerritory(Long id, RTerritory parentTerritory, String title, String type, Integer level) {
    super(id);
    this.parentTerritory = parentTerritory;
    this.title = title;
    this.type = type;
    this.level = level;
    public RTerritory(Long RTerritory, RTerritory parentTerritory, String title,
    String type, Set<RTerritory> RTerritories) {
    setId(RTerritory);
    this.parentTerritory = parentTerritory;
    this.title = title;
    this.type = type;
    this.children = RTerritories;
    public RTerritory(Long id, RTerritory parentTerritory, String title, String type, Integer level, Set<RTerritory> children) {
    super(id);
    this.parentTerritory = parentTerritory;
    this.title = title;
    this.type = type;
    this.level = level;
    this.children = children;
    public Integer getLevel() {
    return level;
    public void setLevel(Integer level) {
    this.level = level;
    public RTerritory getParentTerritory() {
    return this.parentTerritory;
    public void setParentTerritory(RTerritory parent_Territory) {
    this.parentTerritory = parent_Territory;
    public boolean hasParentTerritory() {
         return getParentTerritory() != null;
    public String getTitle() {
    return this.title;
    public void setTitle(String title) {
    this.title = title;
    public String getType() {
    return this.type;
    public void setType(String type) {
    this.type = type;
    public Set<RTerritory> getChildren() {
    return this.children;
    public void setChildren(Set<RTerritory> children) {
    this.children = children;
    public void addChildTerritory(RTerritory territory) throws Exception {
    if (children != null && territory != null) {
    children.add(territory);
    territory.setParentTerritory(this);
    } else {
    throw new Exception("Parameter is null or children is null");// TODO throw exception ?
    public void removeChildTerritory(RTerritory territory) {
    if (children != null && territory != null) {
    children.remove(territory);
    territory.setParentTerritory(null); // TODO territory.setParentTerritory(this.getParentTerritory()) ?
    public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    if (!super.equals(o)) return false;
    RTerritory that = (RTerritory) o;
    if (level != null ? !level.equals(that.level) : that.level != null) return false;
    if (title != null ? !title.equals(that.title) : that.title != null) return false;
    if (type != null ? !type.equals(that.type) : that.type != null) return false;
    return true;
    public int hashCode() {
    int result = super.hashCode();
    result = 31 * result + (title != null ? title.hashCode() : 0);
    result = 31 * result + (type != null ? type.hashCode() : 0);
    result = 31 * result + (level != null ? level.hashCode() : 0);
    return result;
         @Override
         public boolean isReference() {
              return true;
    <?xml version="1.0" encoding="UTF-8"?>
    <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    version="1.0">
    <package>ru.lanit.ps.registry.model</package>
    <entity class="RTerritory" name="RTerritory">
    <table name="reg_r_territory"/>
    <primary-key-join-column name="R_TERRITORY" referenced-column-name="STATUS_ID"/>
    <attribute-override name="id">
    <column name="R_TERRITORY"/>
    </attribute-override>
    <attributes>
    <basic name="title">
    <column length="256" name="TITLE" nullable="false"/>
    </basic>
    <basic name="type">
    <column length="256" name="TYPE" nullable="false"/>
    </basic>
    <basic name="level">
    <column name="LEVEL"/>
    </basic>
    <!--<many-to-one name="parentTerritory" target-entity="RTerritory">
    <join-column name="PARENT_TERRITORY_ID"/>
    <cascade>
    <cascade-persist/>
    <cascade-merge/>
    <cascade-refresh/>
    </cascade>
    </many-to-one>-->
    <one-to-many name="children" mapped-by="parentTerritory" target-entity="RTerritory">
    <cascade>
    <cascade-all/>
    </cascade>
    </one-to-many>
    <transient name="parentTerritory"/>
    <!--<transient name="children"/>-->
    </attributes>
    </entity>
    </entity-mappings>
    If I make "parentTerritory" and "children" transient - all works well. Above workes also (comment out and without transient) on OpenJpa.
    What do I do wrong if I use TopLink?
    This is part of my applicationContext.xml
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceXmlLocation"
    value="/META-INF/persistence.xml"/>
    <property name="jpaVendorAdapter">
    <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter"/>
    </property>
    <property name="loadTimeWeaver">
    <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
    </property>
    </bean
    Thanks a lot.

    Hello.
    Thanks a lot for answer.
    When I comment out and remove transient I obtain the following exception:
    Internal Exception: java.util.NoSuchElementException
         at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:615)
         at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createContainerEntityManagerFactory(EntityManagerFactoryProvider.java:178)
         at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:218)
         at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:251)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1201)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1171)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:261)
         at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1099)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:861)
         at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:421)
         at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
         at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:156)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
         at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
         at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:287)
         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:91)
         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:75)
         at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:65)
         at ru.lanit.ps.registry.VerifyApplicationContext.setUp(VerifyApplicationContext.java:44)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at org.junit.internal.runners.BeforeAndAfterRunner.invokeMethod(BeforeAndAfterRunner.java:74)
         at org.junit.internal.runners.BeforeAndAfterRunner.runBefores(BeforeAndAfterRunner.java:50)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:33)
         at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
         at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
         at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
         at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
         at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
         at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
         at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
         at com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:78)
         at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
    Caused by: Exception [TOPLINK-28018] (Oracle TopLink Essentials - 2.0 (Build b41-beta2 (03/30/2007))): oracle.toplink.essentials.exceptions.EntityManagerSetupException
    Exception Description: predeploy for PersistenceUnit [registry] failed.
    Internal Exception: java.util.NoSuchElementException
         at oracle.toplink.essentials.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:212)
         ... 61 more
    Caused by: java.util.NoSuchElementException
         at java.util.AbstractList$Itr.next(AbstractList.java:427)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor.getPrimaryKeyFieldName(MetadataDescriptor.java:539)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ObjectAccessor.processOneToOneForeignKeyRelationship(ObjectAccessor.java:113)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ObjectAccessor.processOwningMappingKeys(ObjectAccessor.java:190)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.ManyToOneAccessor.process(ManyToOneAccessor.java:106)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.processRelationship(RelationshipAccessor.java:275)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataDescriptor.getMappingForAttributeName(MetadataDescriptor.java:486)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.getOwningMapping(RelationshipAccessor.java:122)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.OneToManyAccessor.process(OneToManyAccessor.java:142)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.RelationshipAccessor.processRelationship(RelationshipAccessor.java:275)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.processRelationshipDescriptors(MetadataProject.java:564)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProject.process(MetadataProject.java:497)
         at oracle.toplink.essentials.internal.ejb.cmp3.metadata.MetadataProcessor.processAnnotations(MetadataProcessor.java:231)
         at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:354)
         at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:584)
         ... 60 more
    Process finished with exit code -1
    I want to say that exception is same and I don't use GlassFish I run Unit test.
    This is my rterritory.xml now:
    <?xml version="1.0" encoding="UTF-8"?>
    <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    version="1.0">
    <package>ru.lanit.ps.registry.model</package>
    <entity class="RTerritory" name="RTerritory">
    <table name="reg_r_territory"/>
    <primary-key-join-column name="R_TERRITORY" referenced-column-name="STATUS_ID"/>
    <attribute-override name="id">
    <column name="R_TERRITORY"/>
    </attribute-override>
    <attributes>
    <basic name="title">
    <column length="256" name="TITLE" nullable="false"/>
    </basic>
    <basic name="type">
    <column length="256" name="TYPE" nullable="false"/>
    </basic>
    <basic name="level">
    <column name="LEVEL"/>
    </basic>
    <many-to-one name="parentTerritory" target-entity="RTerritory">
    <join-column name="PARENT_TERRITORY_ID"/>
    <cascade>
    <cascade-persist/>
    <cascade-merge/>
    <cascade-refresh/>
    </cascade>
    </many-to-one>
    <one-to-many name="children" mapped-by="parentTerritory" target-entity="RTerritory">
    <cascade>
    <cascade-all/>
    </cascade>
    </one-to-many>
    <!--<transient name="parentTerritory"/>
    <transient name="children"/>-->
    </attributes>
    </entity>
    </entity-mappings>
    I can't understand What do I do wrong when I include "one-to-many" and "many-to-one" mapping? I want to note it (above mapping) works rightly if I use OpenJpa and one works rightly with TopLink if I remove one-to-many and many-to-one and do them transient.
    Thanks a lot.
    Message was edited by:
    user610937
    Message was edited by:
    user610937

  • Many-to-one synchronization

    I'm using DataServices to manage hiberate objects.  I have a simple many-to-one relationship between Account and Transaction (an account has many transactions).  I have two DataGrids in my application, one display accounts and their balances(which are derived from the trasactions, there is no balance field) the other displays transactions.  When I edit the accounts, the changes are propogated to the child transactions.  However, when I edit the transactions, the changes are not propagated to the accounts automatically.  If I edit the account or resort the columns it will update the balance.  My data-management-config.xml is below.  My question is, is there a way to make this work or is this not working by design?  I want my Account objects to automatically get the new Transactions associated with them so the balance will update correctly.
    <destination id="AccountHibernate">
         <adapter ref="java-dao" />
         <properties>
              <use-transactions>true</use-transactions>
              <source>flex.data.assemblers.HibernateAssembler</source>
              <scope>application</scope>
              <metadata>
                   <identity property="accountId"/>
                   <one-to-many property="transactions" destination="TransactionHibernate" lazy="false" read-only="true" load-on-demand="true"/>  
              </metadata>
              <network>
                   <session-timeout>0</session-timeout>
              </network>
              <server>
                   <hibernate-entity>budget.data.Account</hibernate-entity>
                   <fill-method>
                        <name>fill</name>
                        <params>java.util.List</params>
                   </fill-method>
                   <fill-configuration>
                        <use-query-cache>false</use-query-cache>
                        <allow-hql-queries>true</allow-hql-queries>
                   </fill-configuration>
              </server>
         </properties>
    </destination>
    <destination id="TransactionHibernate">
              <adapter ref="java-dao" />
              <properties>
                   <use-transactions>true</use-transactions>
                   <source>flex.data.assemblers.HibernateAssembler</source>
                   <scope>application</scope>
                   <metadata>
                        <identity property="transactionId"/>
                        <many-to-one property="account"  destination="AccountHibernate" lazy="false" />
                   </metadata>
              <network>
                   <session-timeout>0</session-timeout>
              </network>
              <server>
                   <hibernate-entity>budget.data.Transaction</hibernate-entity>
                   <fill-method>
                        <name>fill</name>
                        <params>java.util.List</params>
                   </fill-method>
                   <fill-configuration>
                        <use-query-cache>false</use-query-cache>
                        <allow-hql-queries>true</allow-hql-queries>
                   </fill-configuration>
              </server>
         </properties>
    </destination>

    Ed: Thanks for your response, I think I have a better idea of what is going
    on now.
    Regarding the first question: In this case I am just modifying an attribute,
    the relationship between them remains the same.
    I verified that adding a transaction does not update the size of the
    transaction collection the account has if I add the new transaction to the
    transactions collection.  However, if I add the transaction to the
    appropriate accounts list of transactions it does update the collection
    (i.e. there is one more element) but it does not update the balance.  I have
    since changed my balance to a property that is calculated by a query server
    side.  I noticed that even if I change a property on the account, it will
    not update the balance unless I call fill again.
    So I have two questions: 1) is there a way to make the account realize it
    has transactions added to it without adding them directly to the account's
    transaction collection?  2) Is there a way to force the account object to
    refresh the balance (i.e. re-run the query to generate it?).  I realize I
    can call fill() again client side and easily fix this, but I would like to
    do this in a way that causes all clients to have their account balances
    refreshed when the should i.e. I want the server to automatically push the
    new balance property.  If it matters I'm using HibernateAssembler.  Could I
    extend that to achieve this?
    Jim

Maybe you are looking for