JPA 1.x,: parent (one-to-many) and children(many-to-one) in the same table

Hi, excuse me for silly question, but I can't get on with subject.
Please, see my @Entity:
@Entity
public class Department {
     @Id
     @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DEPARTMENT_SEQ")
     @SequenceGenerator(name="DEPARTMENT_SEQ", sequenceName="DEPARTMENT_SEQ", allocationSize=1)
     @Column(name="ID")
     private Long id;
     @Column(name="PARENT_ID")
     private Long parentId;
     @Column(name="LABEL")
     private String label;     
Each department can have one parent (except root department). Each department can have 0-* children (sub-departments).
Is it possible to realize tree structure using JPA 1.x?

This example seems to demonstrate what you want:
http://www.java2s.com/Code/Java/JPA/Relationsononeentity.htm

Similar Messages

  • How to have concurrent CSV upload and manual edit in APEX on the same table

    Hi there,
    my users want to have csv upload and manual edit on apex pages functions together...
    it means they want to insert the data by csv upload and also have interactive report and form on the same table...
    so if user A changes something in csv file...then user B update or delete another record from apex fronted (manually in the apex form)...then after that user A wants to upload the csv file,the record was changed by user B would be overwritten ...
    So how can I prevent it?????

    Hi Huzaifa,
    Thanks for the reply...
    I'm going to use File Browser so that end users can upload the files themselves...
    after editing data by users...a manger going to review it and in case of approval , i need to insert the data to one final table....
    so it needs much effort to check two source tables and in case of difference between table of csv and other one...what to do...

  • Query with many sub-selects on the same table

    Hi,
    Please consider the example below (Oracle 11g):
    create TABLE test1 (order_id number, CODE VARCHAR2(10), VALUE NUMBER);
    insert into test1 VALUES (1, 'A', 100);
    insert into test1 VALUES (1, 'B', 200);
    insert into test1 VALUES (1, 'C', 300);
    insert into test1 VALUES (1, 'D', 400);
    insert into test1 VALUES (2, 'A', 10);
    insert into test1 VALUES (2, 'B', 20);
    SELECT order_id,
           CODE,
           VALUE,
           (SELECT VALUE FROM test1 t1
           WHERE t1.order_id = t.order_id
           AND   t1.code = 'B') b_Value,
           (SELECT SUM(VALUE)/COUNT(*) FROM test1 t1
           WHERE t1.order_id = t.order_id
           AND   t1.code IN ('C', 'D')) cd_Value,
           (SELECT COUNT(*) FROM test1 t1
           WHERE t1.order_id = t.order_id
           AND   t1.code IN ('C', 'D')) cd_qty
    FROM   TEST1 t
    WHERE  CODE = 'A';In my real-life case, I don't have 3 but tens of sub-query columns like those. The performance is OK but I was wondering whether there were a better way in terms of performance and maintainability to write this query.
    I thought of the WITH clause but couldn't see how it could help much.
    Please note that some sub-queries can be more complex than just looking up a column, like in column cd_value/cd_qty.
    Any suggestions?
    Thanks
    Luis

    Simpler, but will go for two table scans. You will have to use outer joins according to your requirement.
    select t1.order_id,
           t1.CODE,
           t1.VALUE,
           max(decode(t2.code,'B',t2.value)) b_value,
           sum(decode(t2.code,'C',t2.value,'D',t2.value,0))/nullif(sum(decode(t2.code,'C',1,'D',1,0)),0)  cd_value,
           sum(decode(t2.code,'C',1,'D',1,0))  cd_qty 
    from TEST1 t1,test1 t2
    where t1.CODE = 'A'
    and t1.ORDER_ID = t2.order_id
    group by t1.order_id,
           t1.CODE,
           t1.VALUEEdited by: jeneesh on Feb 7, 2012 11:54 AM

  • I have two iPads and one iPod Touch and they are using iTunes on the same computer.

    I have two iPads and one iPod Touch and they are using iTunes on the same computer. I have not been able to backup the second iPad. Is there a reason this is happening? iPad one is an iPad 1 and the second is an iPad 2 not sure if this has something to do with it. I just tried to upgrade to IOS 5 and when it went to back up it gave me an error code (-5000). I tried to back up using iTunes and it told me that my backup was corrupted and to delete it and try to back up again. When I went into the device portion where I was instructed to go to delete the backup I found that there was no backup for my iPad just the iPad 1.
    I have synced many times and all of the apps, podcasts, music, etc... show up in iTunes, and iTunes recognizes that is is the second iPad but there is not a backup for it.
    Any Ideas?

    Read this:  How to use multiple iPods, iPads, or iPhones with one computer, http://support.apple.com/kb/HT1495

  • After a month of using CS6 Master, Acrobat ceased functioning. Many other customers with the same problem suggested deactivating Flash Pro to reactivate Acrobat. After following these instructions, the entire suite was deactivated and now dipalys a messag

    After a month of using CS6 Master, Acrobat ceased functioning. Many other customers with the same problem suggested deactivating Flash Pro to reactivate Acrobat. After following these instructions, the entire suite was deactivated and now dipalys a message that our trial that will expire in 10 days (in the middle of an upcoming charity event). Is there any way to reactivate CS6? Is the only option to delete all CS programs? Can we download CS6 again with the same product key?

    In general theory, one now has the Edit button for their posts, until someone/anyone Replies to it. I've had Edit available for weeks, as opposed to the old forum's ~ 30 mins.
    That, however, is in theory. I've posted, and immediately seen something that needed editing, only to find NO Replies, yet the Edit button is no longer available, only seconds later. Still, in that same thread, I'd have the Edit button from older posts, to which there had also been no Replies even after several days/weeks. Found one that had to be over a month old, and Edit was still there.
    Do not know the why/how of this behavior. At first, I thought that maybe there WAS a Reply, that "ate" my Edit button, but had not Refreshed on my screen. Refresh still showed no Replies, just no Edit either. In those cases, I just Reply and mention the [Edit].
    Also, it seems that the buttons get very scrambled at times, and Refresh does not always clear that up. I end up clicking where I "think" the right button should be and hope for the best. Seems that when the buttons do bunch up they can appear at random around the page, often three atop one another, and maybe one way the heck out in left-field.
    While I'm on a role, it would be nice to be able to switch between Flattened and Threaded Views on the fly. Each has a use, and having to go to Options and then come back down to the thread is a very slow process. Jive is probably incapable of this, but I can dream.
    Hunt

  • Have synced my iPhone numerous times and some of the memos in "Voice Memos" on my iPhone wont go over to my iTunes program on my computer. I have a folder titled "Voice Memos" on my iPhone and one of the same name on iTunes on my computer.

    I have synced my iPhone numerous times and some of the memos in "Voice Memos" on my iPhone wont go over to my iTunes program on my computer. I have a folder titled "Voice Memos" on my iPhone and one of the same name on iTunes on my computer. But after I sync I only get 6 out of the 9 voice memos on my iPhone.
    How do I get the rest (or all) of the memos from my iPhone copied to my computer?
    Albro P Michell
    [email protected]

    "I have logged in to my itunes account on a different computer and none of my purchased music is showing up."
    Correct.  it does not magially appear in other places.  It will only be where you put it.
    "I also have plugged my iphone in to get updates but it says I will lose all media and apps if I don't update on the computer where  I sync everything. "
    Correct as well.  Iphone will sync with one computer at a time.  Syncing to another will erase the current content.
    You need to copy everything ( itunes library/contacts/pics/calendars/files/docs) from the old computer, or your backup copy of the old one, to the new one.

  • HT1206 Can I have in one iphone 5 music from more than one itunes accounts?  My daughter and I have our music in the same pc. She and I have iTunes accounts. I have not been able to load in my ophone with my itunes acct music that she purchased in her acc

    Can I have in one iphone 5 music from more than one itunes accounts?  My daughter and I have our music in the same pc. She and I have iTunes accounts. I have not been able to load in my ophone with my itunes acct music that she purchased in her account.  I have not been able to do this. Thanks

    iTunes Match is not sharable across Apple IDs. The best way to get the music on her iPad is to leave hers signed into her Apple ID on the iTunes Store and sync via USB.

  • I'm a school tech coordinator. Many computers and many iPads. How many Apple IDs can I have per device, and how many devices can have the same Apple ID? To make my life easier, I'd like 200 devices to all use the same Apple ID.

    I'm a school tech coordinator. I have many computers and many iPads. I apologize if there is a some place that has all the rules governing the use of Apple IDs. I looked, and I even tried to get the answers from multiple Apple rep's. I couldn't find the answers.
    How many Apple IDs can I have per device?
    I want to use the same computer to sync and backup many iOS devices. The iOS devices would be associated with different Apple IDs.
    I may load apps under a school Apple ID and have users load their own apps under thier own ID.
    How many devices can have the same Apple ID?
    Can I use the same Apple ID on all the computers in a lab?
    Can I use the same Apple ID on all iPads for a particular grade level?
    Are the rules different for iOS devices and computers?
    I know that there are limits on "authorize" and "de-authorize" and how frequently those things can be done.
    Recently I heard that for the life of an iOS device, it can only be associated with five Apple IDs. That is not good for a school giving iPads to students in a 1:1
    To make my life easier, I'd like 200 devices to all use the same Apple ID.

    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html
    It would be best to address your questions there, especially since this is a public forum, and over there you could post more private issues with this set-up. Not to mention, getting more official answers.

  • Our granddaughter has a ipod. She's getting a iphone and a mini idpad.  what is the best way to set them up. Does she need a new apple id and password or would she use the same one she has for her ipod

    our granddaughter has a ipod. She's getting a iphone and a mini idpad.  what is the best way to set them up. Does she need a new apple id and password or would she use the same one she has for her ipod

    Just use the same one on all devices.

  • My family shares one apple id. Is there any way to make an apple id for each member of my family and have it all connected to the same credit card and have the same previous downloads open to download by signing in to each members personal apple id?

    My family shares one apple id. Is there any way to make an apple id for each member of my family and have it all connected to the same credit card and have the same previous downloads open to download by signing in to each members personal apple id?

    Hi cindy,
    If you all have individual Apple IDs, then you would be able to dowload music from a shared iTunes library on a computer, but you would not be able to sign on each individual ID on an iOS device in order to download music purchased under the original Apple ID without a 90-day waiting period between sign-ons.
    Here's what I mean:
    If you were to sign on a new Apple ID on, say, an iPhone, and then were to purchase and download some music from iTunes, then you would have to wait 90 days before you could sign on the old Apple ID to that iPhone in order to download previously purchased material (and vice versa).
    However, if all of the music purchased by that origjnal Apple ID is in an iTunes library on a shared computer, then you can hook up the device and selectively sync any music in that library to the device. You can also sign on any of the Apple IDs to that shared iTunes library and purchase music to be added to the library.
    You would need to authorize the computer for each of the new Apple IDs.
    Each of the Apple IDs would also be able to download that music purchased either by syncing to the iTunes library on the computer or by downloading it OTA on the device.
    So, each Apple ID can download music, movies, etc. purchased with that Apple ID OTA to the device. Also each Apple ID can sync any music, movies, etc. that are in the iTunes library on the computer regardless of who purchased them.
    The only other thing you would need to remember is that if an App needed to be updated, then the original Apple ID that was used to purchase that App would come up, and the password that goes with that Apple ID would be required to do the update.
    Hope that helps,
    GB

  • How can I align two different text row in the same table in two different way (one centered and the other one on the left)?

    Hi,
    I want to center two different text row that are in the same table but one on the center and the other one on the left. I put a <span> tag hoping that it has been overwhelmed the table's class properties The .bottomsel's font-family and the .Cig84's font-family and colour work but the text-align don't: they're both on the left.
    These are my source and CSS codes:
    Source:
    <table width="600" border="0">
      <tr>
        <td class="bottomref"><p><span class="bottomsel">| <a href="index.html" target="_self">Main</a> | <a href="about.html" target="_self">About</a> | <a href="clients.html" target="_self">Clients</a> | <a href="contact.html" target="_self">Contact</a> |</span><br />
          <span class="credits">Credits: <span class="Cig84">Cig84</span></span></p></td>
      </tr>
    </table>
    CSS:
    .bottomsel {
      text-align: center;
      font-family: Georgia, "Times New Roman", Times, serif;
    .credits {
      text-align: left;
    .Cig84 {
      color: #F00;
      font-family: "Comic Sans MS", cursive;

    Use paragraph tags with CSS classes.
    CSS:
         .center {text-align:center}
         .left {text-align:left}
    HTML:
    <table width="600" border="0">
      <tr>
        <td class="bottomref">
              <p class="center">This text is center aligned</p>
              <p class="left">This text is left aligned</p>
        </td>
      </tr>
    </table>
    Nancy O.

  • My i phone got stolen and i got a new one with the same number but how do i synch it up with my old contacts?  i thought i could do from ituned but it hasnt worked!!

    hello,
    my i phone got stolen and i got a new one with the same number, but i cant get it to synch up with my itunes to make it like my old phone! can you please tell me how i do this. i need all my contacts and content etc etc.

    Plug it into iTunes and tell iTunes what to sync to the device.

  • Ever since installing iCloud and Lion my computer is slow or freezes.  The color wheel comes on and My work stops.  I have only a small window of time where my computers will function normally during the day. I know many others that have the same problem.

    Ever since installing iCloud and Lion my computer is slow or freezes.  The color wheel comes on and My work stops.  I have only a small window of time where my computers will function normally during the day. I know many others that have the same problem. I'll get 20-30 minutes of work done and then a sync or something comes on, the color wheel of death shows up, and my productivity is shot.  I have to shut the computer down the hard way!  when it comes back up, it is still either frozen or slow.  I've checked in at the genius bar and all they say is that there have been some problems that Apple is trying to fix.  It effects Mail, Contacts, Safari, Calendar....yeah, pretty much everything.  My iPhone and iPad are not effected as much so I end up doing what I can with them.  I've seen the blogs out there and understand that many have the same problem.  I have been waiting to read about a fix but I have found nothing!  Any ideas?

    Not enough free space on the startup disk can slow the system down.
    Right or control click the MacintoshHD icon. Click Get Info. In the Get Info window you will see Capacity and Available. Make sure there's a minimum of 15% free disk space.
    For startup issues...  open System Preferences > Users & Groups - Login Items. Delete any apps listed there then restart your mac.
    And disable the Lion "resume" feature.
    Open System Preferences > General
    Deselect:   Restore windows when quitting and re-opening apps
    And Spotlight may be indexing... you can turn that off > Turning Off Spotlight | Mac Tricks And Tips

  • Admin and Task servers as one in the same

    I open up the Remote Desktop software, and select 1 computer from the list. I then click on the "Install" icon and drag a .pkg file inside of the "Packages" area. I check off the radio button that says "Run this task from: The Task Server on this computer" and click the "Install" button.
    I get a progress bar that runs infinitley and a message that says "The targetd computer, "<computer name>", is currently idle. It doesn't matter if the computer is up and running, or if it is offline. It says the same thing regardless and never installs the package.
    If I decide not to "Run this task from: The Task Server on this computer" and instead "Run this task from: This application" then it works prefectly. I just can't seem to install from the local task server, which means I have to wait until this machine is online before I can manually run it, which means there's a problem with the way I set up the Task server.
    Does anyone have any idea what's wrong with my installation? I have gone into "Remote Desktop -> Preferences -> Task Server" and made sure "Use Task Server on this computer" was selected, and it is. I am NOT using 2 different serial number for 2 different and separate copies of ARD3 for both an Admin + Task Server. I am, however, expecting the Task Server and Admin Server to run as one in the same. If this is not possible then perhaps the Documentation needs updating? From http://images.apple.com/server/docs/ARDTaskServer.pdf I read: "You can run the Task Server on either the administrator computer or a dedicated remote computer. The default Task Server is the administrator computer on which you installed Remote Desktop.". This means the Admin and Task Servers can run as one in the same, no? Please let me know if this is incorrect.

    Update: Please refer to the post with the title of "Possible to run both an Admin Server and Task server from the same host?". Basically the answer to this problem is that there isn't one. I've called apple support and it's been confirmed that an Admin server and Task server CANNOT be run from the same installation on the same host. I suppose you could say the answer is to buy another license of ARD3 and run it in a separate host, but for some of us this isn't an option - especially for a very small startup.

  • Phone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    Both my iphone and my husbands iphone ring at the same time when only one of us is being called. How can I stop this from happening?

    This post has already been answered. Why are you plugging your own site with an answer that has already been given? Not to mention that the information you are handing out is incorrect. There is no bug, there is no patch, and no one needs to delete any email addresses. If you take the time to read the posts with the correct answers, you will see that the solution is totally different than the erroneous one you have posted.
    GB

Maybe you are looking for