EJB 3, OneToMany that Acts As Tree, or Parent Child relationship support?

(Sorry for the RoR reference)
I first searched the forum and found this post that came close, but not exactly what I'm needing since my table doesn't reference the PK:
http://forum.java.sun.com/thread.jspa?forumID=13&threadID=767913
I have a table called Folder that represents a folder hierarchy. It has a 'Path' field and a 'Parent' field, and of course 'ID'. Each Folder knows its parent by the 'Parent' field, which references 'Path', not* 'ID'. Both are Strings.
To find all the children of a Folder, the sql for a PreparedStatment might look something like this (shared for clarity of the situation):
SELECT * FROM Folder
WHERE Parent = ?Question:
What are the proper annotations in EJB 3 / JPA to allow this kind non-primary key parent/child relationship mapping?
Can I specify a named query that handles the logic and then reference it in the OneToMany annotation? Other cool tricks?
Here is what I am trying (no runtime errors, but no results either). (Example simplified)
@Entity
@Table(name = "Folder")
@NamedQueries(value = {@NamedQuery(.......)})
public class Folder implements Serializable {
    @Id
    @Column(name = "ID", nullable = false, updatable = false)
    private Integer folderID;
    @Column(name = "Path", nullable = false)
    private String path;
    @Column(name = "Parent")
    private String parent;
    // v Here's the kicker v
    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    @JoinTable(name="Folder",
        joinColumns={@JoinColumn(name="Parent")},
        inverseJoinColumns={@JoinColumn(name="Path")})
    private List<Folder> children;
    // getters and setters ....
}Thanks!

It looks like the relationship is bi-directional.
Will this work...
// Parent.java
@Entity
public class Parent implements java.io.Serializable {
@Id
public Long parentId;
@OneToMany(cascade=CascadeType.PERSIST,mappedBy="parent")
public Collection<Child> children;
// Child.java
@Entity
public class Child implements java.io.Serializable {
@Id
public Long childId;
@ManyToOne
public Parent parent;  // target of mappedBy
}Then, in your code (a session facade?), you'll create the parent first, create the children, then add the children to the parent. Your code is also responsible for maintaining the reference back to the parent.
Parent p = new Parent();
for(int i=0; i<10; i++) {
  Child c = new Child();
  p.children.add(c);
  c.parent = p;
em.persist(p);

Similar Messages

  • How do I create parent/child relationship between objects? so that if I change one, I change all

    I have multiple instances of an object, and I would like to make any changes that I put on one of these objects to perpetuate and change on the other instances of the object

    turn your object into a symbol, and place multiple instances of it on the artboard, when you edit the symbol all instances will update.

  • Form acting as child in parent child reference

    Hi guys,
    I have a custom fields form.
    This form basically uses other forms in our systems information as a parent-child relationship.
    It uses FORM NAME and ID from that form name to query custom fields form i.e.
    If you go into for example a customer form, then the custom form needs to trigger that you have gone into this form, and pass to custom the form name and the primay key thats queried.
    Also if you navigate away to another form (not closing it) and navigate back it should also trigger the execute query in this other form, is this possible?
    Basically we have 500 forms and a requirement has come in to add custom fields to all these forms so createing one form that contains the custom fields and having a triggr mechanism to execute query on this was the cleanest way i could attempt to achieve this, i do not want to amend 500 forms!
    Thanks

    Hai,
    For this create global variables to store the FORM_NAME and ID, and assign to those global variables on each master forms WHEN-WINDOW-ACTIVATED Trigger. And in the WHEN-WINDOW-ACTIVATED Trigger of the child form, query the details using those global variables. and use insert into or update statements to update.
    Regards,
    Manu.

  • Merge data/result sets that are't parent/child?

    Hi:
    I've seen a few examples of making a data template so that a BI report can have master/detail data. They make a Q1 data set and a Q2 data set with a bind variable to link the two in a parent/child relationship.
    But what I need is effectively a UNION. I have the same table on multiple database instances and I want to show the grouped results in one report as if it all came from one table. The master/detail examples have a section defining grouping but they group by Q1 (see here)
    http://blogs.oracle.com/BIDeveloper/data_template/
    and I need to group by a column that is in Q1 and Q2 to "merge" the two data sets.
    Has anyone done this?
    Thanks.

    I've messed up what I had! lol
    I'll try and recreate things tomorrow and get it to you, thanks.
    I seem to be having some quirks with all this (or I'm just confused). I initially had a data model that selected a few columns and a count(*) an grouped the results. I modified the data model to not have the count but every time I do "insert table/chart" in RTF the count column shows up as a possible column to move over with >>. I've re-opened the document so it should have the latest data model. Is this normal? A bug? Am I just lost?
    Thanks.

  • Access EJB from Servlet that in different archive?

    <font class="mediumtxt">package kyro.ejb.session;
    import javax.ejb.*;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    @Stateless(name="StandAlone")
    @Remote(StandAlone.class)
    public class StandAloneBean
    implements StandAlone, StandAloneLocal
    public StandAloneBean() {
    public String sayHello() {     
    return "sayHello";
    I want to access ejb from servlet that .war and .jar not in single .ear. I want to try that just with annotation not xml descriptor cause is easy to understand for me. I use Glassfish. But i can't lookup that ejb. How can i lookup that ejb with jndi? Can't you give me example of servlet to access that? I not use JNDI.properties, are that caused i can't access my ejb? I just thing .war and.jar in one server, are i have to used JNDI.properties. can you explain how to use JNDI.properties in servlet or separate file?
    </font>

    But i can't lookup that ejb. How are you trying and what exception is occurring?
    How can i lookup that ejb with jndi? [https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html|https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html]
    m

  • Full browser window placeholder that acts like background image fill?

    I want to be able to set full browser window placeholder that acts like the background image fill function, but be able to then build in a multi-anchored horizontal parallax.  The effect is like we have a background image fill, but can slide horizontally between pages as if they are in a slide show.  Simultaneously, content inside the placeholder such as longer paragraphs of text can scroll down - on top of the image layer, but inside the borders of the image placeholder.  For a clear example of this, see this website: http://argonautinc.com/
    I've read and searched but to no avail.  I'm only about one week into Muse, so please forgive me if this is  super simple!   Thanks, Nico

    Hi Nico_Cineaste,
    You can achieve the design by using Fullscreen Slideshow in MUSE as object.
    Open any page in MUSE , click on the "Object" >> Slideshow >> Fullscreen.
    Click on your blank web page.
    This will give you a full screen slideshow.
    You can now design as per your requirement.
    Thanks
    Prabhakar Kumar

  • Textarea - create String that acts like a single character

    Hi guys,
    I am trying to create a string in a textarea that acts like a single character. By this, I mean that the user cannot edit the contents of that section of text. Here's an example:
    Textarea text:
    [Number of Iterations] * 35 / 200
    I want the [Number of Iterations] to be read-only. In addition, if the user tries to delete the beginning or end of [Number of Iterations], the whole thing is deleted. If possible, I would like cursor operations to treat it like a single character as well (i.e. to go from |[Number of Iterations] to [Number of Iterations]| takes a single right button press).
    Some commercial applications like Microsoft Word do this with Automatically created text in documents (like page numbers and date stamps) and I was wondering if I could do the same thing using a Textarea.
    Any help would be greatly appreciated.
    Thanks in advance,
    Steve

    A JTextPane allows you to add components to the text pane. So you might be able to create a JLabel with your desired text and insert the label into the text pane.

  • I am using Photoshop CC2014 15.00.  In the pop-up menu for the Fill command there is a place for Scripted patterns.  Within that part, the tree and the picture frame are grayed. Why?   I've seen demonstrations on how to use the feature but mine doesn't wo

    I am using Photoshop CC2014 15.00.  In the pop-up menu for the Fill command there is a place for Scripted patterns.  Within that part, the tree and the picture frame are grayed.
    Why?   I've seen demonstrations on how to use the feature but mine doesn't work.  I checked the updates and I have the current version.
    Thanks.      LM

    I am running CC 2014.2.1 and I've updated to Yosemite. Not seeing tree or frame as an option in the menu. Coworker still on Mavericks has it.

  • Working through TC/IP with a PPc that acts as real executor

    Hi to all, there is my question.
    Do i have the possibility/a way to tell to teststand to load all steps and then wait for the answers? I have to work (using TC/IP) with a PPc that acts as real executor of the requested steps.

    Dear Josè,
    I get from you each Step in TestStand is actually sort of TCP/IP Client/Server that sends a TCP Command to a PPC ( PowerPC?) executor and eventually waits for an answer or timeout. If This is the case seems you are actually Loading and Running each step at the same time thus you'll have to deal with Parallel execution on the TS side and a considerable amount of data that potentially will flood the ethernet.
    My suggestion is to carefully design the Client/Server architecture. 
    I'd use a structure that will enable opening a series of connection in the setup section and closing it in the cleanup. Then I'd build up a custom step type that given the connection and the command will write it. Then it's your choice it the command take always the same time to execute and are supposed to be executed in a sequence the custom step will also wait for the answer. Otherwise you have to figure out wich is the better way to wait for the result.
    Please note I may be in my suggestion wrong, I don't have enough info and I can't help you further than this.
    Bottom line my final suggestion is.
    Take a breath and feed yourself with the following philosophical question.
    Given the Hardware Can it be run this fast ?
    It has to be sequential or parallel ?
    May I send more command in a row and then wait for all the ansewer toghether ?
    Will the answer arrive in the same order ? or they'll be messed Up ?
    What will happen if one of the anser times out ?
    And so on and so on, long before writing a single line of code.
    You'll eventyally get out of it with a bunch of specs and schemes that will help you design a robust test framework.
    Good Work!
    And have a good day
    FiloP
    It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong.
    Richard P. Feynman

  • Programatically creating ADF Tree with nodes,child nodes & links?

    Hi,
    Currently I am using Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660. Please provide me detailed code for programatically creating ADF Tree with nodes, child nodes and links in it.
    Thanks,
    Vik

    You need to create a model for the tree. ADF has a build in model that you can use to build your own tree.
    This is what you need to write in your JSPX:
    <af:tree summary="Navigation" id="treeNav" value="#{pageFlowScope.treeNavigationBackingBean.model}"
               var="node" contextMenuSelect="true" rowSelection="single" fetchSize="30">   
           <f:facet name="nodeStamp">
          <af:outputText id="txtText" value="#{node.text}"/>
        </f:facet>
    </af:tree>This is the code to retreive the model:
      public TreeModel getModel() {
        if(model == null)
            model = new ChildPropertyTreeModel(instance,"children");
        return model;
      }instance contains the actual tree. I build it in the constructor of my managed bean:
        public BeanTreeNavigation() {
          ArrayList<TreeItem> rootItems = new ArrayList<TreeItem>();
          TreeItem node1 = new TreeItem("Root node");
             ArrayList<TreeItem> level1 = new ArrayList<TreeItem>();
             TreeItem level1Node1 = new TreeItem("Level1 Node1");
              level1.add(level1Node1);
           node1.setChildren(level1);
           rootItems.setChildren(node1); 
          this.setListInstance(rootItems);
          root = rootItems;
      public void setListInstance(List instance) {
        this.instance = instance;
        model = null;
      }The TreeItem class is not a default one. I created it myself. You can make of it whatever you want:
        public class TreeItem {
          private String text;
           private List<TreeItem> children = null;
           public TreeItem(String text){
            this.text = text;
            public void setText(String text) {
                this.text = text;
            public String getText() {
                return text;
            public void setChildren(List<TreeItem> children) {
                this.children = children;
            public List<TreeItem> getChildren() {
                return children;
            }I wrote the TreeItem as an inner class of the managed bean.
    The most important part is the getModel methode. There you need to specify an Object and the name of the getter that will return a List of the children.
    Hope this helps.
    Edited by: Yannick Ongena on Feb 22, 2011 7:30 AM

  • Anyone else keep getting "Updating tree" ever since Pro App Support update?

    Ever since one of the last updates for Pro Applications administered by Apple, Logic Pro 7 has been starting with an additional annoyance. I keep getting a little load window that says:
    "Updating tree, please wait"
    Every time I start it up. Anyone else get this? It is pretty annoying. A push to get me to buy Logic 8 so I can appreciate Logic 8's 'superior speed'?
    Not like getting Logic 8 would make too much a difference there, being that I am a Power PC user . . . but that is for another topic.
    Thanks!

    okay, your recommendation sounded straight-forward enough. Thank you, by the way. But when I went into Logic to turn it off, I couldnt find where I could. And that is probably a part of the problem-- I don't know how I turned it on in the first place. Any tips on how I get there? Is there a key command for it? If so, that must be the way I accidentally turned it on. Thanks, again!!

  • I have a problem with my Iphone 4s since I did my first update at your Itunes, the bluetooth and the WiFi it is not workinhg anymore.  It is sad that companies like apple are not able to support thier sofware and business.  I went to a apple store at Sout

    I have a problem with my Iphone 4s since I did my first update at your Itunes, the bluetooth and the WiFi it is not workinhg anymore.
    It is sad that companies like apple are not able to support thier sofware and business.
    I went to a apple store at South Park, Charlotte NC,
    and found out the worst customer service (in my case)
    They don't have answers and don't understand about  "dont let any customer go away sad or mad"
    I explain to them that I did everything they said to fix the problem, even to dounload the iOS 6.1.3
    that was supposed to fix the problem.
    they said fix the problem in other phones but not in mine.
    So here I am with no wifi and bluetooth, with apple technicians and experts that don't know what to do with the problem that the sofware they developed cause in my iphone 4s.
    and the solution is for me to pay $199.00 US dollars for a problem that I did not cause.
    wich means to buy something else from apple to fix a problem that it is not my fault.
    Great! what a convenient solution.
    I would like to have an answer from you guys and see if someone there have a better answer for me that shows support, values and integrity as a grest company with solutions for your customers.
    Dont think that I want a new phone, I want mine fixed if is possible.
    Thank you very much and God Bless you!

    Apple isnt here. this is a user based forum for technical questions. The solution is to restart, reset, and restore as new which is in the manual after that get it replaced for hard ware failure. if your within your one year warranty its replaced if it is out of the warranty then it is 199$

  • My iphon 5 said "only compatible sim cards from a supported carrier may be used to activate iphone. please insert the sim card that came with ur phone or visit a supported carrier's store to receive a replacement sim card" what do i do???

    my iphon 5 said "only compatible sim cards from a supported carrier may be used to activate iphone. please insert the sim card that came with ur phone or visit a supported carrier's store to receive a replacement sim card" what do i do??? i leave in diferent country now!!!???(((

    in many countries to make phones seem less expensive
    carriers pay most of the phones price for the customer
    but this come at the cost of the phone only being able to work
    with the carrier this is called a sim lock
    the only people who can remove a sim lock is the carrier which
    the phone is sim locked to they been doing it like that for at least 20 years

  • Since I upgraded my iPod Touch 4G, the HDMI connector to my TV (that I bought from Apple) is no longer supported. Can this be corrected in a short period? Thanks

    As stated in the title, since I installed iOS6 on my iPod Touch 4G, the HDMI connector that I bought from Apple is no longer supported/recognized...
    A bit of a problem, when you buy an accessory to be able to watch videos on any HDMI enabled TV....
    Too bad that nobody checked on it before releasing the OS...
    Is there a solution to be released soon (like very soon)????

    Sometime the following works.
    - A reset. Nothing is lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Restore from backup
    - Restore to factory settings/new iPod.

  • I guess the problem come from me or I really need those contacts before he calls me for it. I'll try some method that I got from some responders on your support website. Do you have or can you recommand any software that can solve this problem?

    I guess the problem come from me but I really need those contacts before he calls me for it. I'll try some method that I got from some responders on your support website. Do you have or can you recommand any software that can solve this problem?
    One more thing. I just update my iphone that my boss gave to me but it seems to be like it giving me some trouble. My iphone was updated not too long and was successful. I try to lock into it and it telling me emergency call. I plug it to my itune and it telling me that the sim card is not valid or supported. So I inserted my sim card that I usually use to call and it still saying the same. Please help me get into it.

    And as far as paying for phone support, here are a few tips:
    If you call your carrier first and then they route you to Apple, you usually don't have to pay for phone support.
    If you are talking to Apple and they ask you to pay a support fee, ask if you can get an exception this time.  That usually works once, but they keep track of the times you've been granted such an exception.
    If you still end up paying the support fee, that fee only applies if it's not a hardware related issue.  In other words, if it can be fixed by just talking over the phone and following Apple's instructions, then the fee applies.  But if your device is deemed to have a hardware failure that caused the issue, then the fee should not apply, and you can ask for it to be waived after the fact.
    This forum is free, and almost all of the technical support articles the Apple tech advisors use are available on this website.  Literally 99% of what they can do over the phone is just walking you through the publicly available support articles.  In other words, you're paying the fee to have them do your research for you.  It's like hiring a research consultant to go look stuff up in the public library so you don't have to.  You're capable of doing it; you'd just rather pay someone to do it for you.
    It's like Starbucks.  You know how to make coffee.  Everyone knows how to make coffee.  And Starbucks coffee isn't any better than what you could make at home for far less.  But you want the convenience.  So you're really paying a convenience fee.  Milk is more expensive at 7-Eleven than it is at the grocery store... because it's a convenience store.

Maybe you are looking for

  • Movie Rental Download

    I recently rented a movie but when I try to download it it says "Error downloading. Tap to retry." I keep tapping and it says the same thing, I even tried downloading in iTunes on the computer and it will not download. How do I fix this or just remov

  • Validation for Profit center in MM01

    hi all, i have to validate the Profit Center field coming in Tcode MM01 in view COSTING1, but i dont know that how wud i do? actually here in my company there are three plant and three profit center and i have to restrict the user for wrong input. bu

  • SAP LSO Course Evaluatio Form format in LSO_PV15

    Hi, We have a requirement from client about Course Evaluation Form. - When we open the course evaluation form in T.Code PHAP_CATALOG or in the learning portal the format is displayed in PDF or smart form. - When the course administrator opens the sam

  • Pdf not loading

    Whwn I click on a link with a pdf it doesn't open. I'm on the latest Safari and Windos 64 bit  versiuon

  • Reg : Internal error

    Hi , I am getting  exception while clicking action from portal "Exception condition "INTERNAL_ERROR" raised., error key: RFC_ERROR_SYSTEM_FAILURE: com.sap.aii.proxy.framework.core.BaseProxyException." Function module and JCo' s are  working properly.