JPA, how to write a service to persist objects in a 1-to-many relationship

i am using JPA for data persistence. i have two objects that are involved in a one-to-many relationship. for example, i have an object, Company, and Company can have one or more, Employee. i then define a service called, CompanyDao, which has the usual create-read-update-delete (CRUD) operations. my problem is that when i instantiate a new Company with new Employees and call CompanyDao.create(Company), i keep getting an exception.
Cannot add or update a child row: a foreign key constraint fails (`demo`.`employee`, CONSTRAINT `employee_ibfk_1` FOREIGN KEY (`companyId`) REFERENCES `company` (`id`))
i have an intuition on why this is happening. when i call CompanyDao.create(Company), the newly instantiated Company doesn't yet have an id (its unique identifier). that is why when it tries to insert the Employees of Company, i get this problem. but, my question is, shouldn't JPA take care of all of this for me? shouldn't it know that it is creating a new Company, will have to insert it, will have to retrieve the unique id (generated) and then populate the employee table with this id?
i was thinking about this problem, and i thought maybe i could insert the company first and then the employees later. however, the problem is, once i insert the company, how do i get its unique id? i cannot query for it any other way (i.e. by name) that will return a unique result.
if anyone knows of a good, comprehensive tutorial on how to write a service demonstration CRUD operations on objects with one-to-many relationship, please let me know.

Hi,
Could you please send CompanyDao.create(Company) code so that we can dig in to problem.
Regards
Murali N

Similar Messages

  • How to write sync service in sybase unwired platform

    Hi
    How to write sync service in sybase unwired platform?
    Thanks in advance....

    Hi!
    A RESTful web service (also called a RESTful web API) is a simple web service implemented using HTTP and the principles of REST. It is a collection of resources, with three defined aspects:
    - the base URI for the web service, such as http://example.com/resources/
    - the Internet media type of the data supported by the web service. This is often JSON, XML or YAML but can be any other valid Internet media type.
    - the set of operations supported by the web service using HTTP methods (e.g., POST, GET, PUT or DELETE).
    On Sybase Unwired WorkSpace you can select, in Enterprise Explorer, REST Web Services connection defining a resource base URL and URI template, and then using this as MBO defining HTTP method and parameters.
    Try this:
    http://en.wikipedia.org/wiki/Representational_State_Transfer
    and this:
    http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01283.0155/doc/html/fre1261416769728.html
    http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01283.0155/doc/html/fre1261424660910.html

  • How to write Sync service in ABAP

    Dear Experts,
                  i m very new to ABAP dev, can anybody help me how to write a sync service in ABAP and how to call a function module in to that sync service.
                   My requirement is i want to upload the data from the clint and download the data to client from the backend. i had written the function module to create a customer in CRM, now i want to push the data to create a customer from the client, for this i need to write a sync service for above requirement,
                plz help me out how to write a sync service.
                           Regards
                            eswar

    Hi Jyotirmoy,
    Check this thread for Subquery
    http://help.sap.com/saphelp_nw04/helpdata/en/dc/dc7614099b11d295320000e8353423/content.htm
    Correlated, non-scalar subquery:
    REPORT demo_select_subquery_1.
    DATA: name_tab TYPE TABLE OF scarr-carrname,
          name  LIKE LINE OF name_tab.
    SELECT  carrname
      INTO  TABLE name_tab
      FROM  scarr
      WHERE EXISTS ( select  *
                       FROM  spfli
                       WHERE carrid   =  scarr~carrid AND
                             cityfrom = 'NEW YORK'        ).
    LOOP AT name_tab INTO name.
      WRITE: / name.
    ENDLOOP.
    This example selects all lines from database table SCARR for airlines that fly from New York.
    Scalar subquery:
    REPORT demo_select_subquery_2.
    DATA: carr_id TYPE spfli-carrid VALUE 'LH',
          conn_id TYPE spfli-connid VALUE '0400'.
    DATA: city  TYPE sgeocity-city,
          lati  TYPE p DECIMALS 2,
          longi TYPE p DECIMALS 2.
    SELECT  SINGLE city latitude longitude
      INTO  (city, lati, longi)
      FROM  sgeocity
      WHERE city IN ( select  cityfrom
                        FROM  spfli
                        WHERE carrid = carr_id AND
                              connid = conn_id      ).
    WRITE: city, lati, longi.
    This example reads the latitude and longitude of the departure city of flight LH 402 from database table SGEOCITY.
    Thanks,
    Vinay

  • How to write Tuxedo service with conversational mode ?

    Is there anyone do me a favour and tell me how to write the conversational service
    ? I failed to use tpconnect to set up the converational communication channel
    since the returned error number from tpconnect is 6.
    Many Thanks !

    "huchacha" <[email protected]> wrote:
    >
    Is there anyone do me a favour and tell me how to write the conversational
    service
    ? I failed to use tpconnect to set up the converational communication
    channel
    since the returned error number from tpconnect is 6.
    Many Thanks !Hello,
    1. TPNOENT=6 (from atmi.h).
    2. After tpconnect (from Tuxedo docs):
    [TPENOENT] Cannot initiate a connection to svc
    because it does not exist or is not a conversational service.
    3. Check SERVER section in ubbconfig,
    for example (from Tuxedo docs):
    CONV = {Y | N} specifies whether or not the server
    is a conversational server.
    Connections can only be made to conversational servers,
    and rpc requests (via tpacall() or tpcall()) can only be made
    to non-conversational servers. The default is N.
    Best regards,
    Vladimir

  • How to write the text into text objects

    Hi,
    I have one requirements . from the web we get the delivery line item based pallet numbers info with Quntity .
    How to write the line item level pallet information in the the Delivery line items text element "pallet info" .
    Any function module to write the text data into text elements in SAP like READ_TEXT.
    please give your valuable suggisions .
    Thanks &Regards
    Sai.

    Try:
    CREATE_TEXT
    SAVE_TEXT

  • How to write Web Service Log to a file in Java

    Hi..
    I have a requirement that I need to maintain Log file of my web service which is deployed on OC4J server.
    Is there any API for this ? Or any other way to do it ?
    Regards,
    Ajay

    Hi..
    Thanks.
    Instead of using Logging API, I created own class to handle Log.
    But my issue is When Ever I am appending Log to already created file the following Line is also appending.
    <?xml version = '1.0' encoding = 'UTF-8'?>I want this Line only one time in each log file.
    What should I do for this ?
    Regards,
    Ajay

  • How to create web services with complex objects as parameters

    Hi,
    Not sure if this is the right place, but...
    I'm using Netbeans 5.5 and trying to learn web services.
    Creating a simple web service with simple parameters like strings and integers is nice and easy. I'm now trying to take the next step, and create a web service with a more complex schema as a parameter.
    I've tried two approaches, and hit dead ends on both:
    (1) Define my complex schema as an xsd file, and then create a WSDL file. Creating the schema and saving it in my EFB project works fine; when I try to create a new WSDL file, the IDE gives me a button to import external schemas - which is where the problem is: the Browse simply won't find my newly created schema file.
    (2) Define a Java class (in this case, it's a fairly simple example containing a single ArrayList), and then use the IDE to generate a web service from Java. The IDE does this fine, but I now have no idea how to consume or test the web service - I don't know where to look for the WSDL that has presumably been generated, and I'm also a bit iffy over what answers to give the WSDL creator about port names etc.
    Ideally, I'd prefer to get approach 1 to work - can someone point me in the direction of a sensible tutorial for these things?
    (Happy to carry on using Netbeans 5.5 or to revert to Sun Studio Enterprise, which I was playing with before.)
    All help appreciated, Thanks

    - For NetBeans related questions, nbusers mailing list is more suited. It is often visited by NetBeans experts.
    http://www.netbeans.org/community/lists/top.html
    ...[email protected]
    The NetBeans users mailing list. General discussion of NetBeans use, this is the place to ask for help and to help others.... (There is a 'Subscribe' button next to the above that you can use to subscribe to the list).
    Can you try posting this question on nbusers list?
    - SJSE 8.1 is based on an older version of NB (NB5.0).
    You should definitely continue with NetBeans, since all development is now being done in NetBeans; all the major JSE modules have been moved to opensource at netbeans.org and are all being developed there. There are as yet no future plans to work on further releases for JSE.
    Please check out http://www.netbeans.org for more details.

  • How to write ABAP Logic in SAP Query to fetch records from many Tables

    Hi Expert,
    I have one requirement, want to display all BOM (Equipment BOM, Function Location BOM and Meterial BOM) from a particular plant.
    List of tables as below:
    EQST: Equipment to BOM Link
    TPST: Link Between Functional Location and BOM
    MAST: Material to BOM Link
    STPO:BOM item
    Requirement: When user enters Plant then SAP Query should execute and fetch all BOMs (as mentioned above) from STPO Table.
    I have done so far is as follows:
    I create User Group, Infoset and SAP Query.
    While creating INFOSET, i used 4 tables (EQST,TPST,MAST & STPO) and link between then is as follows:
    STPO-STLNR ---> EQST-STLNR : Left Outer Join
    STPO-STLNR ---> TPST-STLNR : Left Outer Join
    STPO-STLNR ---> MAST-STLNR : Left Outer Join
    Now its showing all BOM from all plants though I enter one Plant value.
    Please advise me to write SAP Query and Logic to fetch all BOM from selected Plant Value.
    Thanks,
    Jay.
    Edited by: jaykrishna007 on Jul 29, 2011 11:41 AM

    Hi FCannavo,
    Thanks for your quick reply.
    See, now I changed my Infoset design.
    I added one Plant Table (T001W) and then
    T001W-WERKS--->EQST-WERKS
    T001W-WERKS--->MAST-WERKS
    T001W-WERKS--->TPST-WERKS
    and then
    EQST-STLNR--->STPO-STLNR
    MAST-STLNR--->STPO-STLNR
    TPST-STLNR--->STPO-STLNR
    on selection screen, user will enter Plant Value.
    Now its showing some records, but i dont think so i would be correct output or not, please guide me whether it is correct or not?
    Thanks,
    Jay.

  • How to write data to existing file using spool command?

    Hi,
    I am calling a stored procedure from a shell script. This stored procedure is having a CLOB object as an OUT parameter. How to write the data in CLOB object a existing file which is there in my client system. Below is the shell and sql scripts.
    Shell script
    ( echo "hello" ) > /root/file.txt
    sqlplus -s $user/$pass@$tns @/root/proc.sql /root/file.txt << EOF
    EOFSQL script
    set pages 0
    set trimspool off
    set serveroutput off
    set feedback off
    set term off
    set echo off
    variable out CLOB
    define file='&1'
    begin
    pack.proc(:out);
    end;
    spool &file
    select :out from dual;
    spool offThis code writes contents of the OUT variable to file.txt, but my existing data ('hello') is lost. Please help me.
    I figured the it...Use append in the spool command... :)
    Edited by: Balaji on Jul 19, 2012 8:55 PM

    >
    Hi Balaji
    I figured the it...Use append in the spool command... :Please mark the thread as answered as per the FAQ.
    Paul...

  • How to write WSDD file to deploy web service

    I write a server code,I want to deploy it as service,but I don't know how to write WSDD file?I use AXIS and SOAP
    I need help,thanks a lot.
    Regards
    William
    2.24

    Yes, put your wsdd with your class files. But if you want AdminClient to work correctly, be sure all environement variables are set correctly.
    Me, I never use it, I prefer to modify directly the server-config.wsdd

  • How to write a program that runs on a port like a deamon or service?

    hi,
    how to write a program in java that runs on a port like a deamon or service, accepts requests from client, process the request and gives responce.
    for ex. tomcat runs on 8080 port as deamon or service.
    is it socket programming? if yes please give me a simple program which runs on a specific port.
    ex. a program running on a port talking two integers and return the total.
    thanks and regards,
    moses.

    I suggest you read
    [http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html]
    For more
    [http://www.google.co.uk/search?q=serversocket+tutorial]

  • How to write the CMD command for restarting all obi services?

    Hi Experts,
    BIEE:11.1.1.6
    How to write the CMD command for restarting all obi services automatically by windows task scheduler?
    I am try to write the code as below, but it does not work. Please help me to review it and check what I am missing.Thanks.
    Or is there any better method for solving my requirement ? Please share me.Thanks very much.
    cd C:\InstallPath\OBIEE\instances\instance1\bin
    opmnctl stopall
    opmnctl startall
    I am facing the problem that it does not excute the 'opmnctl startall' code, which will be stopped after 'opmnctl stopall',
    So how to modify the command ?Thanks

    See if any of the these are useful or solves your query -
    4.5.2 Using a Windows Service to Start and Stop System Components
    http://docs.oracle.com/cd/E23943_01/bi.1111/e10541/components.htm#BABEEAAI
    4.5.3 Using the Oracle BI Systems Management API to Programmatically Start and Stop Oracle Business Intelligence
    http://docs.oracle.com/cd/E23943_01/bi.1111/e10541/components.htm#BABFGICA
    Edited by: Abhi on May 8, 2013 4:44 AM

  • How to verify whether the persistence unit objects are persistent or not?

    How to verify whether the persistence unit objects are persistent or not?
    I have successfully configure and deploy the Employees object as a persistence unit in Oracle Coherence according to the guide of Chapter 6 of Tutorial for Oracle Coherence 3.5.
    Using the RunEmployeeExample script, I have got the right results. I can see that after the cache object is updated, the database table (Employees) is also updated accordingly. The following is the output:
    2009-11-05 11:09:55.043/53.467 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member(Id=2, Timestamp=2009-11-05 11:09:54.867, Add
    ress=192.168.8.80:8089, MachineId=24656, Location=process:1684, Role=OracleRunEmployeeExample) joined Cluster with senior member 1
    2009-11-05 11:09:55.604/54.028 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member 2 joined Service Management with senior memb
    er 1
    2009-11-05 11:09:56.885/55.309 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): TcpRing: connecting to member 2 using TcpSocket{Sta
    te=STATE_OPEN, Socket=Socket[addr=/192.168.8.80,port=8089,localport=4084]}
    2009-11-05 11:09:57.847/56.281 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member 2 joined Service JpaDistributedCache with se
    nior member 1
    2009-11-05 11:09:57.917/56.341 Oracle Coherence GE 3.5.2/463 <D5> (thread=DistributedCache:JpaDistributedCache, member=1): Service JpaDistributed
    Cache: sending ServiceConfigSync containing 258 entries to Member 2
    2009-11-05 11:10:04.086/62.510 Oracle Coherence GE 3.5.2/463 <D5> (thread=DistributedCache:JpaDistributedCache, member=1): Deferring the distribu
    tion due to 1 pending configuration updates
    [EL Info]: 2009-11-05 11:10:14.36--ServerSession(2883071)--EclipseLink, version: Eclipse Persistence Services - 1.1.1.v20090430-r4097
    [EL Info]: 2009-11-05 11:10:22.312--ServerSession(2883071)--file:/C:/JDeveloper/mywork/AppJPA/JPA/classes/-JPA login successful
    2009-11-05 11:10:24.305/82.729 Oracle Coherence GE 3.5.2/463 <D5> (thread=DistributedCache:JpaDistributedCache, member=1): 3> Transferring 128 ou
    t of 257 primary partitions to member 2 requesting 128
    2009-11-05 11:10:25.697/84.121 Oracle Coherence GE 3.5.2/463 <D4> (thread=DistributedCache:JpaDistributedCache, member=1): 1> Transferring 129 ou
    t of 129 partitions to a node-safe backup 1 at member 2 (under 129)
    2009-11-05 11:10:25.857/84.281 Oracle Coherence GE 3.5.2/463 <D5> (thread=DistributedCache:JpaDistributedCache, member=1): Transferring 0KB of ba
    ckup[1] for PartitionSet{128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
    152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180,
    181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
    210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
    239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256} to member 2
    2009-11-05 11:10:40.678/99.102 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): TcpRing: disconnected from member 2 due to a kill r
    equest
    2009-11-05 11:10:40.678/99.102 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member 2 left service Management with senior member
    1
    2009-11-05 11:10:40.678/99.102 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member 2 left service JpaDistributedCache with seni
    or member 1
    2009-11-05 11:10:40.708/99.132 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member(Id=2, Timestamp=2009-11-05 11:10:40.708, Add
    ress=192.168.8.80:8089, MachineId=24656, Location=process:1684, Role=OracleRunEmployeeExample) left Cluster with senior member 1
    2009-11-05 11:10:40.879/99.303 Oracle Coherence GE 3.5.2/463 <Info> (thread=DistributedCache:JpaDistributedCache, member=1): Restored from backup
    128 partitions
    2009-11-05 11:10:40.879/99.303 Oracle Coherence GE 3.5.2/463 <D4> (thread=DistributedCache:JpaDistributedCache, member=1): 0, 1, 2, 3, 4, 5, 6, 7
    , 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 4
    4, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80
    , 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 11
    3, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
    2009-11-05 11:28:39.800/1178.224 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member(Id=2, Timestamp=2009-11-05 11:28:39.635, A
    ddress=192.168.8.80:8089, MachineId=24656, Location=site:metsys.metex.com,machine:mw12,process:1752, Role=CoherenceConsole) joined Cluster with s
    enior member 1
    2009-11-05 11:28:40.231/1178.655 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member 2 joined Service Management with senior me
    mber 1
    2009-11-05 11:28:41.633/1180.057 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): TcpRing: connecting to member 2 using TcpSocket{S
    tate=STATE_OPEN, Socket=Socket[addr=/192.168.8.80,port=8089,localport=4143]}
    2009-11-05 11:30:01.658/1260.082 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=1): Member 2 joined Service DistributedCache with sen
    ior member 2But I cannot verify if the persistence unit is still persistent.
    Edited by: jetq on Nov 5, 2009 11:49 AM

    I start a Coherence Console in another Windows Command Prompt as the following:
    D:\coherence\bin>  coherence.cmd
    ** Starting storage disabled console **
    java version "1.6.0_11"
    Oracle Coherence Version 3.5.2/463
    Grid Edition: Development mode
    Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
    2009-11-05 11:57:22.167/9.734 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=n/a): Service Cluster joined th
    e cluster with senior service member n/a
    2009-11-05 11:57:22.197/9.764 Oracle Coherence GE 3.5.2/463 <Info> (thread=Cluster, member=n/a): Failed to satisfy the v
    ariance: allowed=16, actual=20
    2009-11-05 11:57:22.197/9.764 Oracle Coherence GE 3.5.2/463 <Info> (thread=Cluster, member=n/a): Increasing allowable va
    riance to 17
    2009-11-05 11:57:22.677/10.244 Oracle Coherence GE 3.5.2/463 <Info> (thread=Cluster, member=n/a): This Member(Id=3, Time
    stamp=2009-11-05 11:57:22.392, Address=192.168.8.80:8089, MachineId=24656, Location=process:460, Role=CoherenceConsole,
    Edition=Grid Edition, Mode=Development, CpuCount=1, SocketCount=1) joined cluster "cluster:0xD3FB" with senior Member(Id
    =1, Timestamp=2009-11-05 11:09:09.738, Address=192.168.8.80:8088, MachineId=24656, Location=process:1816, Role=Coherence
    Server, Edition=Grid Edition, Mode=Development, CpuCount=1, SocketCount=1)
    2009-11-05 11:57:22.737/10.304 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=n/a): Member 1 joined Service
    Management with senior member 1
    2009-11-05 11:57:22.737/10.304 Oracle Coherence GE 3.5.2/463 <D5> (thread=Cluster, member=n/a): Member 1 joined Service
    JpaDistributedCache with senior member 1
    2009-11-05 11:57:23.108/10.675 Oracle Coherence GE 3.5.2/463 <D5> (thread=Invocation:Management, member=3): Service Mana
    gement joined the cluster with senior service member 1
    2009-11-05 11:57:23.759/11.326 Oracle Coherence GE 3.5.2/463 <D5> (thread=TcpRingListener, member=3): TcpRing: connectin
    g to member 1 using TcpSocket{State=STATE_OPEN, Socket=Socket[addr=/192.168.8.80,port=4168,localport=8089]}
    SafeCluster: Name=cluster:0xD3FB
    Group{Address=224.3.5.2, Port=35463, TTL=4}The previous output shows that this Coherence console (the client side) has already joined the JPA server.
    But the following output shows us that this console cannot access the Employees cache and cannot get the object entry. Why?
    Map (?): cache Employees
    2009-11-05 12:11:41.653/869.220 Oracle Coherence GE 3.5.2/463 <Info> (thread=main, member=3): Loaded cache configuration
    from "jar:file:/D:/coherence/lib/coherence.jar!/coherence-cache-config.xml"
    2009-11-05 12:11:43.055/870.622 Oracle Coherence GE 3.5.2/463 <D5> (thread=DistributedCache, member=3): Service Distribu
    tedCache joined the cluster with senior service member 3
    <distributed-scheme>
      <!--
      To use POF serialization for this partitioned service,
      uncomment the following section
      <serializer>
      <class-
      name>com.tangosol.io.pof.ConfigurablePofContext</class-
      name>
      </serializer>
      -->
      <scheme-name>example-distributed</scheme-name>
      <service-name>DistributedCache</service-name>
      <backing-map-scheme>
        <local-scheme>
          <scheme-ref>example-binary-backing-map</scheme-ref>
        </local-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
    Map (Employees): list
    2009-11-05 12:11:48.402/875.969 Oracle Coherence GE 3.5.2/463 <Error> (thread=main, member=3):
    java.lang.RuntimeException: Storage is not configured
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.onMissing
    Storage(DistributedCache.CDB:9)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.ensureReq
    uestTarget(DistributedCache.CDB:33)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.sendParti
    tionedRequest(DistributedCache.CDB:31)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.size(Dist
    ributedCache.CDB:13)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap$EntrySet.
    size(DistributedCache.CDB:1)
            at com.tangosol.util.ConverterCollections$ConverterEntrySet.size(ConverterCollections.java:2720)
            at com.tangosol.coherence.component.application.console.Coherence.doList(Coherence.CDB:74)
            at com.tangosol.coherence.component.application.console.Coherence.processCommand(Coherence.CDB:442)
            at com.tangosol.coherence.component.application.console.Coherence.run(Coherence.CDB:39)
            at com.tangosol.coherence.component.application.console.Coherence.main(Coherence.CDB:3)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at com.tangosol.net.CacheFactory.main(CacheFactory.java:1400)Edited by: jetq on Nov 5, 2009 12:18 PM

  • How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column

    Please Help!!!
    How to write a case statement for the totals column of two different years (2013 and 2014) of the same month so that I can get a +/- column.
                                      January 2014         January
    2013                            +/-
                    Region   Entry   Exit  Total    Entry   Exit   Total   (Total of Jan2014-Total of Jan2013)
                    A               2         3      
    40        5       7        30                    40-30= 10

    What is a table structure? Sorry cannot test it right now..
    SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
    FROM tbl
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How can I use XStream to persist complicated Java Object  to XML & backward

    Dear Sir:
    I met a problem as demo in my code below when i use XTream to persist my Java Object;
    How can I use XStream to persist complicated Java Object to XML & backward??
    See
    [1] main code
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import com.thoughtworks.xstream.XStream;
    import com.thoughtworks.xstream.io.xml.DomDriver;
    public class PhoneList {
         ArrayList<PhoneNumber> phones;
         ArrayList<Person> person;
         private PhoneList myphonelist ;
         private LocationTest location;
         private PhoneList(String name) {
         phones = new ArrayList<PhoneNumber>();
         person = new ArrayList<Person>();
         public ArrayList<PhoneNumber> getphones() {
              return phones;
         public ArrayList<Person> getperson() {
              return person;
         public void addPhoneNumber(PhoneNumber b1) {
              this.phones.add(b1);
         public void removePhoneNumber(PhoneNumber b1) {
              this.phones.remove(b1);
         public void addPerson(Person p1) {
              this.person.add(p1);
         public void removePerson(Person p1) {
              this.person.remove(p1);
         public void BuildList(){
              location = new LocationTest();
              XStream xstream = new XStream();
              myphonelist = new PhoneList("PhoneList");
              Person joe = new Person("Joe, Wallace");
              joe.setPhone(new PhoneNumber(123, "1234-456"));
              joe.setFax(new PhoneNumber(123, "9999-999"));
              Person geo= new Person("George Nixson");
              geo.setPhone(new PhoneNumber(925, "228-9999"));
              geo.getPhone().setLocationTest(location);          
              myphonelist.addPerson(joe);
              myphonelist.addPerson(geo);
         public PhoneList(){
              XStream xstream = new XStream();
              BuildList();
              saveStringToFile("C:\\temp\\test\\PhoneList.xml",convertToXML(myphonelist));
         public void saveStringToFile(String fileName, String saveString) {
              BufferedWriter bw = null;
              try {
                   bw = new BufferedWriter(
                             new FileWriter(fileName));
                   try {
                        bw.write(saveString);
                   finally {
                        bw.close();
              catch (IOException ex) {
                   ex.printStackTrace();
              //return saved;
         public String getStringFromFile(String fileName) {
              BufferedReader br = null;
              StringBuilder sb = new StringBuilder();
              try {
                   br = new BufferedReader(
                             new FileReader(fileName));
                   try {
                        String s;
                        while ((s = br.readLine()) != null) {
                             // add linefeed (\n) back since stripped by readline()
                             sb.append(s + "\n");
                   finally {
                        br.close();
              catch (Exception ex) {
                   ex.printStackTrace();
              return sb.toString();
         public  String convertToXML(PhoneList phonelist) {
              XStream xstream = new  XStream(new DomDriver());
              xstream.setMode(xstream.ID_REFERENCES) ;
              return xstream.toXML(phonelist);
         public static void main(String[] args) {
              new PhoneList();
    }[2].
    import java.io.Serializable;
    import javax.swing.JFrame;
    public class PhoneNumber implements Serializable{
           private      String      phone;
           private      String      fax;
           private      int      code;
           private      String      number;
           private      String      address;
           private      String      school;
           private      LocationTest      location;
           public PhoneNumber(int i, String str) {
                setCode(i);
                setNumber(str);
                address = "4256, Washington DC, USA";
                school = "Washington State University";
         public Object getPerson() {
              return null;
         public void setPhone(String phone) {
              this.phone = phone;
         public String getPhone() {
              return phone;
         public void setFax(String fax) {
              this.fax = fax;
         public String getFax() {
              return fax;
         public void setCode(int code) {
              this.code = code;
         public int getCode() {
              return code;
         public void setNumber(String number) {
              this.number = number;
         public String getNumber() {
              return number;
         public void setLocationTest(LocationTest bd) {
              this.location = bd;
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(location);
            f.getContentPane().add(location.getControls(), "Last");
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
         public LocationTest getLocationTest() {
              return location;
         }[3].
    package test.temp;
    import java.io.Serializable;
    public class Person implements Serializable{
         private String           fullname;
           @SuppressWarnings("unused")
         private PhoneNumber      phone;
           @SuppressWarnings("unused")
         private PhoneNumber      fax;
         public Person(){
         public Person(String fname){
                fullname=fname;           
         public void setPhone(PhoneNumber phoneNumber) {
              phone = phoneNumber;
         public void setFax(PhoneNumber phoneNumber) {
              fax = phoneNumber;
         public PhoneNumber getPhone() {
              return phone ;
         public PhoneNumber getFax() {
              return fax;
        public String getName() {
            return fullname ;
        public void setName(String name) {
            this.fullname      = name;
        public String toString() {
            return getName();
    }[4]. LocationTest.java
    package test.temp;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class LocationTest extends JPanel implements ChangeListener
        Ellipse2D.Double ball;
        Line2D.Double    line;
        JSlider          translate;
        double           lastTheta = 0;
        public void stateChanged(ChangeEvent e)
            JSlider slider = (JSlider)e.getSource();
            String name = slider.getName();
            int value = slider.getValue();
            if(name.equals("rotation"))
                tilt(Math.toRadians(value));
            else if(name.equals("translate"))
                moveBall(value);
            repaint();
        protected void paintComponent(Graphics g)
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(ball == null)
                initGeom();
            g2.setPaint(Color.green.darker());
            g2.draw(line);
            g2.setPaint(Color.red);
            g2.fill(ball);
        private void initGeom()
            int w = getWidth();
            int h = getHeight();
            int DIA = 30;
            int padFromEnd = 5;
            line = new Line2D.Double(w/4, h*15/16, w*3/4, h*15/16);
            double x = line.x2 - padFromEnd - DIA;
            double y = line.y2 - DIA;
            ball = new Ellipse2D.Double(x, y, DIA, DIA);
            // update translate slider values
            int max = (int)line.getP1().distance(line.getP2());
            translate.setMaximum(max);
            translate.setValue(max-padFromEnd);
        private void tilt(double theta)
            // rotate line from left end
            Point2D pivot = line.getP1();
            double lineLength = pivot.distance(line.getP2());
            Point2D.Double p2 = new Point2D.Double();
            p2.x = pivot.getX() + lineLength*Math.cos(theta);
            p2.y = pivot.getY() + lineLength*Math.sin(theta);
            line.setLine(pivot, p2);
            // find angle from pivot to ball center relative to line
            // ie, ball center -> pivot -> line end
            double cx = ball.getCenterX();
            double cy = ball.getCenterY();
            double pivotToCenter = pivot.distance(cx, cy);
            // angle of ball to horizon
            double dy = cy - pivot.getY();
            double dx = cx - pivot.getX();
            // relative angle phi = ball_to_horizon - last line_to_horizon
            double phi = Math.atan2(dy, dx) - lastTheta;
            // rotate ball from pivot
            double x = pivot.getX() + pivotToCenter*Math.cos(theta+phi);
            double y = pivot.getY() + pivotToCenter*Math.sin(theta+phi);
            ball.setFrameFromCenter(x, y, x+ball.width/2, y+ball.height/2);
            lastTheta = theta;  // save theta for next time
        private void moveBall(int distance)
            Point2D pivot = line.getP1();
            // ball touches line at distance from pivot
            double contactX = pivot.getX() + distance*Math.cos(lastTheta);
            double contactY = pivot.getY() + distance*Math.sin(lastTheta);
            // find new center location of ball
            // angle lambda = lastTheta - 90 degrees (anti-clockwise)
            double lambda = lastTheta - Math.PI/2;
            double x = contactX + (ball.width/2)*Math.cos(lambda);
            double y = contactY + (ball.height/2)*Math.sin(lambda);
            ball.setFrameFromCenter(x, y, x+ball.width/2, y+ball.height/2);
        JPanel getControls()
            JSlider rotate = getSlider("rotation angle", "rotation", -90, 0, 0, 5, 15);
            translate = getSlider("distance from end",  "translate", 0, 100, 100,25, 50);
            JPanel panel = new JPanel(new GridLayout(0,1));
            panel.add(rotate);
            panel.add(translate);
            return panel;
        private JSlider getSlider(String title, String name, int min, int max,
                                  int value, int minorSpace, int majorSpace)
            JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, value);
            slider.setBorder(BorderFactory.createTitledBorder(title));
            slider.setName(name);
            slider.setPaintTicks(true);
            slider.setMinorTickSpacing(minorSpace);
            slider.setMajorTickSpacing(majorSpace);
            slider.setPaintLabels(true);
            slider.addChangeListener(this);
            return slider;
    }OK, My questions are:
    [1]. what I generated XML by XSTream is very complicated, especially for object LocationTest, Can we make it as simple as others such as Person object??
    [2]. after I run it, LocationTest will popup and a red ball in a panel will dsiplay, after I change red ball's position, I hope to persist it to xml, then when I read it back, I hope to get same picture, ie, red ball stiil in old position, How to do that??
    Thanks a lot!!

    Positive feedback? Then please take this in a positive way: if you want to work on persisting Java objects into XML, then GUI programming is irrelevant to that goal. The 1,000 lines of code you posted there appeared to me to have a whole lot of GUI code in it. You should produce a smaller (much smaller) example of what you want to do. Calling the working code from your GUI program should come later.

Maybe you are looking for