Urgent : java bean having bidirectional one to many relationship

Hi,
We have complex requirement in our application.
We need to copy java bean having bidirectional one to many relationship to another javabean having bidirectional one to many relationship..
E.g
Class Basket1 {
public String color;
pubic String type;
public List<Basket1> basketList = new ArrayList()
Class Basket2 {
public String color;
pubic String type;
public List<Basket2> basketList = new ArrayList()
We need to exact copy Basket1 to Basket2. We are in trouble to copy List of child because we do not have how many child Basket1 have of same type..
Can someone help us how we can implement such kind of complex object bidirectional one to many relationship??

I can't see anything bidirectional about these relationships. What I can see is a couple of BasketN classes that look identical so I don't know why they both exist, and they both contain lists of themselves as members, which suggests some kind of tree structure. Nothing bidirectional there. I can see tat these things can form circular object graphs but I don't see why you would want to do that.
We need to exact copy Basket1 to Basket2And I don't know what that means. Please explain.

Similar Messages

  • How to insert data in a one-to-many relationship

    How do you insert data into the client, my model entity beans have a one-to-many relationship.
    PARENT ENTITY BEAN
    PARENT-ID
    PARENT-NAME
    The ejbCreate(Integer parentID,String name)
    CHILD ENTITY BEAN
    CHILD-ID
    CHILD-NAME
    PARENT-ID(foreign key of PARENTID).
    ejbCreate(Integer parentID,String name,String foreignparentID)
    In a jsp page i collect the parent details and 3 corresponding chld details in a text box.
    Can you please tell me how do i proceed from here...
    ie. how to i insert data into the entity beans..
    Do i pass the child as a collection, and within parents ejbCreate() method do i lookup for the childs home interface and insert one -by -one from the collection.
    1. Considering the above example, can some one pls tell how the ejbCreate() mehod signatures, for the parent and child entity beans should be.
    2. Pls also show some sample client code as to how to make an insertion.
    3. In case you are passing a collection of child data, then in what format does one have to insert into a collection and also how does the container know how to insert the values in the child table , bcoz we are passing as a collection.
    4.In case collections cannot be inserted do we need to iterate into the collection in parent's ejbCreate() method, and manually insert into the database of the childtable, thereby creating child entity beans.
    Thanks for your time and support...
    regards
    kartik

    Hi,
    3. In this case of course child's ejbCreate(and postCreate) looks like
    ejbCreate(Integer childID,String name,ParentLocal parent) {
    setId(Id);
    setName(name);
    ejbPostCreate(Integer childID,String name,ParentLocal parent) {
    setParent(parent);
    Here you don't need IDs, but it happens only using Locals, not Remotes, if I'm not wrong. Container does it itself.
    1. Of course, if you have parent.getChildren() and parent.setChildren() then you don't need any loops, but it should be done anyway in postCreate, because in ejbCreate there no parent exists yet.
    Once more 3: example - I'm using JBoss 3.2.5 as EJB container. It has tomcat inside and EJB and JSP+Struts use the same jvm. It means for me that I don't need to use remote interfaces, just locals. And in this case I can implement ejb-relations. So, a have the abstract method parent.getChildren() which returns Collection of ChildLocal - s and method parent.setChildren(Collection childrenLocals) which creates/modifies children by itself.
    I have not used remotes for a long time, but as I remember it was not possible to implement ejb-relations using remotes.
    regards,
    Gio

  • One-to-many relationship within one bean

    hello all,
    Does S1 support a container managed one-to-many relationship to itself?
    I used the verifer to verify my DD and the error is reported. (this prototype is migrated from weblogic6.1 and I use the S1 migration tool for the DD generation)
    -----------------database schema-----------------
    CREATE TABLE t_class_a
    c_name VARCHAR2(255),
    one_class_a_for_ma2918_id VARCHAR2(32), /* untruncated name: one_class_a_for_many_class_a_id */
    object_id VARCHAR2(32) NOT NULL
    CREATE UNIQUE INDEX t_class_a_id_PK ON t_class_a ( object_id );
    ALTER TABLE t_class_a ADD ( CONSTRAINT t_class_a_id_PK PRIMARY KEY ( object_id ) USING INDEX );
    ALTER TABLE t_class_a ADD ( CONSTRAINT FK_0 FOREIGN KEY ( one_class_a_for_ma2918_id ) REFERENCES t_class_a ( object_id ) );
    ---------------------------ejb-jar.xml------------------
    <abstract-schema-name>ClassABean</abstract-schema-name>
    <cmp-field>
    <field-name>objectId</field-name></cmp-field>
    <cmp-field>
    <field-name>name</field-name></cmp-field>
    <primkey-field>objectId</primkey-field>
    <relationships>
    <ejb-relation>
    <ejb-relation-name>manyClassA_oneClassA</ejb-relation-name>
    <ejb-relationship-role>
    <description>optional</description>
    <ejb-relationship-role-name>OneClassA-in-manyClassA_oneClassA</ejb-relationship-role-name>
    <multiplicity>One</multiplicity>
    <relationship-role-source>
    <ejb-name>ClassAEJB</ejb-name></relationship-role-source>
    <cmr-field>
    <cmr-field-name>manyClassAsForOneClassA</cmr-field-name>
    <cmr-field-type>java.util.Collection</cmr-field-type></cmr-field></ejb-relationship-role>
    <ejb-relationship-role>
    <description>optional</description>
    <ejb-relationship-role-name>ManyClassA-in-manyClassA_oneClassA</ejb-relationship-role-name>
    <multiplicity>Many</multiplicity>
    <relationship-role-source>
    <ejb-name>ClassAEJB</ejb-name></relationship-role-source>
    <cmr-field>
    <cmr-field-name>oneClassAForManyClassA</cmr-field-name>
    </cmr-field>
    </ejb-relationship-role>
    </ejb-relation>
    </relationships>
    -----------sun-cmp-mapping.xml--------
    <sun-cmp-mapping>
    <schema>mySchema</schema>
    <entity-mapping>
    <ejb-name>ClassAEJB</ejb-name>
    <table-name>T_CLASS_A</table-name>
    <cmp-field-mapping>
    <field-name>objectId</field-name>
    <column-name>OBJECT_ID</column-name></cmp-field-mapping>
    <cmp-field-mapping>
    <field-name>name</field-name>
    <column-name>C_NAME</column-name></cmp-field-mapping>
    <cmr-field-mapping>
    <cmr-field-name>manyClassAsForOneClassA</cmr-field-name>
    <column-pair>
    <column-name>T_CLASS_A.OBJECT_ID</column-name>
    <column-name>T_CLASS_A.ONE_CLASS_A_FOR_MA2918_ID</column-name></column-pair></cmr-field-mapping></entity-mapping></sun-cmp-mapping></sun-cmp-mappings>
    I beleive the migration tool missing the cmr-filed mapping for the oneClassAForManyClassA relation role.
    but even if I add this mapping it still can't pass the verifiy.
    So do I miss any thing or I can conclude S1 not support this one-to many self relation?
    Any hint would be welcome.

    It does.
    There is a known problem with parsing self-referenced relationship info - the one side (with <multiplicity> Many) must be the first in the <ejb-relation> entry.
    Regards,
    Marina

  • One to many relationship in hibernate

    I am very much new to hibernate,
    for testing purpose I am using JPA annotations and hibernate.
    While testing one to many relationship , I got a problem
    I have a PurchaseOrder class and OrderLine class having one to many relationship.
    package orderpackage;
    import java.util.ArrayList;
    import java.util.List;
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    @Entity
    public class PurchaseOrder {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      @OneToMany(cascade=CascadeType.ALL,mappedBy="order")
      private List <OrderLine> orderLine = new ArrayList<OrderLine>();
      public PurchaseOrder(String orderName) {
      this.orderName = orderName;
      public List<OrderLine> getOrderLine() {
      return orderLine;
      public void setOrderLine(List<OrderLine> orderLine) {
      this.orderLine = orderLine;
      private String orderName;
      public int getId() {
      return id;
      public void setId(int id) {
      this.id = id;
      public String getOrderName() {
      return orderName;
      public void setOrderName(String orderName) {
      this.orderName = orderName;
    OrderLine.java
    package orderpackage;
    import javax.persistence.CascadeType;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.ManyToOne;
    @Entity
    public class OrderLine {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
      private String itemName;
      private int qty;
      @ManyToOne(cascade=CascadeType.ALL)
      private PurchaseOrder order;
      public OrderLine(String itemName, int qty) {
      this.itemName = itemName;
      this.qty = qty;
      public PurchaseOrder getOrder() {
      return order;
      public void setOrder(PurchaseOrder order) {
      this.order = order;
      public int getId() {
      return id;
      public void setId(int id) {
      this.id = id;
      public String getItemName() {
      return itemName;
      public void setItemName(String itemName) {
      this.itemName = itemName;
      public int getQty() {
      return qty;
      public void setQty(int qty) {
      this.qty = qty;
         OrderTest.java
    package orderpackage;
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    public class OrderTest {
      public static void main(String[] args) {
      PurchaseOrder order = new PurchaseOrder("order no 1");
      OrderLine orderLine1 = new OrderLine("item1",25);
      OrderLine orderLine2 = new OrderLine("item2",28);
      OrderLine orderLine3 = new OrderLine("item3",38);
      OrderLine orderLine4 = new OrderLine("item4",48);
      order.getOrderLine().add(orderLine1);
      order.getOrderLine().add(orderLine2);
      order.getOrderLine().add(orderLine3);
      order.getOrderLine().add(orderLine4);
      SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
      Session session = sessionFactory.openSession();
      session.beginTransaction();
      session.persist(order);
      session.getTransaction().commit();
      session.close();
    I can see Order and Order Line are get persisted but Order Line table don't have order_id populated automatically. Please help me out.

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

  • One to many relationships

    Hi I have a big problem :)
    I want to use one to many relationships.
    One yable with primary key, foreign key view_id. The second table on the many side with primary key view_id and another primary key.
    The problem is that ejbc gives the followin error:
    " [java] In relationship 'ViewType-SView', role 'ViewType-Has-SView', a weblogic-relationship-role element contains the wrong number of column mappings. A single column mapping must be given for each primary key column in the bean referenced by the mapping."
    And that makes no sense for me. Any ideas?

    weblogic-relationship-role element column mappings should be the same as defined in
    <ejb-relationship-role>
    <multiplicity></multiplicity>
    </ejb-relationship-role>
    Erno wrote:
    Hi I have a big problem :)
    I want to use one to many relationships.
    One yable with primary key, foreign key view_id. The second table on the many side with primary key view_id and another primary key.
    The problem is that ejbc gives the followin error:
    " [java] In relationship 'ViewType-SView', role 'ViewType-Has-SView', a weblogic-relationship-role element contains the wrong number of column mappings. A single column mapping must be given for each primary key column in the bean referenced by the mapping."
    And that makes no sense for me. Any ideas?

  • One to Many relationship in CMP

    Hi,
    How to create CMP entity bean that can map One To Many relationship?
    Thanks.
    (Actually, i have post this question in "Java programming" forum becoz i couldn't find the EJB link in forum main page...)

    Hello Friend,
    Go carefully through the RosterApp example in the J2EE tutorial.
    It sure is going to help you.
    See each and every tab and the values in the deployment tool.
    Best of Luck

  • Struggling with a one to many relationship in a sub-report

    Post Author: Scott_tansley
    CA Forum: General
    I have a database schema as per below: tblENQUIRY                 tblDatasheets                  tblReportParasIRSID (PK)       1 --> &  IRSID (FK)                       UID (PK)Attribute1                     SHEETID (PK)     1 > &  SHEETID (FK)Attribute2                     Attribute1                         LIST_ORDER                         tblStandardParasAttribute3                     Attribute2                         PARA_CODE (FK)    & < 1   CODE     (PK)etc...                            Attribute3                                                                     TEXT                                   etc...
    The PROBLEM I am a Crystal Reports Newbie, and having to work through things bit by bitu2026  I've managed to achieve quite a lot, but I'm totally stuck with this and would appreciate some help. I need to create a report (essentially a letter and some datasheets) around a one-to-many relationship, which I have managed to compile using a main report (for the one &#91;tblENQUIRY&#93;) and sub report (for the many &#91;tblDatasheets&#93;).  Essentially I need a covering letter, then the u2018manyu2019 datasheets, and then a number of other pages (which are largely static text). I have created a main report which includes the covering letter, holds a subreport for the datasheets, and then contains the text for the additional pages.  This all works fine, and I get the correct number of datasheets for each main report. My problem stems from the use of this sub report.  This sub-report needs to hold some attribute values for each datasheet, which is fine.  However, on each datasheet page I need to have some paragraphs, which are held in another one to many relationship.  Each datasheet may have up to six paragraphs held as a code in tblReportParas, with a relationship to the text as held in tblStandardParas. My original thought would have been to embed another sub report, containing the values from tblStandardParas!TEXT, into the first sub report.  However, I have found that it is not possible to have a sub-report inside another sub-report.  I had seperated the first sub-report out from the main report, and then embedded another sub-report into it.  This worked fine until I tried to stitch the sub-report back into the main report (at which point the sub-sub-report dissapeared from view). I have therefore reworked my sub-report a little, and the attribution is now stored in a pageheader, with the tblStandardParas!TEXT in a detail section below it.  This almost works! The only problem is that there is no relationship between the pageheader and detail sections.  To clarify, I would expect to have one datasheet, with the attribution at the top, and then the six paras below.  Then, the same on the next page (assuming there is a second datasheet) for that report.  Instead, I get the correct attribution, but the detail section actually gives every paragraph in the database, no matter which datasheet/or report it related to!  I therefore need to limit the detail section to only show those paragraphs where the SHEETID in tblReportParas is the same as the tblDatasheets SHEETID. Any offers of advice would be appreciated.

    Post Author: Scott_tansley
    CA Forum: General
    I managed to resolve this myself in the end.  I moves the tblEnquiry data into report header/footer sections, this allowed me to add the tblDatasheets information into the details section, which gave me multiple pages - and then finally, the Paragraphs were added through the use of a sub report. 
    There's probably an even better way, but for now it works, it's quick - and so I'm going to go with it!
    Thanks for your interest.

  • Summarizing data in a one-to-many relationship

    Post Author: Bob Amiral
    CA Forum: General
    I use an order tracking system that has a one to many relationship between the main order information file and the line items file.  For each order, there can be one or more items in the items file.  I am having no luck trying to summarize data in such a way that shows selected information from the order file with only a summary from the item file on one line.  Instead, the reports expands by adding a line for each and every entry from the item file that relates to the order.
    How can I summarize data from the item file to show only one line of item data in the same line as the order data?

    Post Author: Charliy
    CA Forum: General
    Group by Order #
    Suppress the Detail (and possibly the Group Header, depending on how you want it to look)
    Put Running Totals in the Group Footer that reset on change of group.

  • One to many relationship leads to recursion?

    Hi,
    I've created a web services function which returns an object retrieved from a database using the persistence api (the class was generated by the Netbeans 5.5 "Entity Class from Database" feature.
    I can successfully return an object which has no foreign keys. However, when I try to retrieve an entity which is on either side of a 1:N relationship, I receive a stackOverflowError.
    Here's my sample schema (I'm using Derby bundled with SJAS 9 for testing)
    create table Address (
       Id int not null,
       StreetName varchar(255),
       City varchar(255),
       PostalCode varchar(255),
       Party int,
       primary key (Id)
    create table Party (
       Id int,
       Name varchar(255),
       primary key(Id)
    alter table Address add constraint foreign key (Party) references Party;So as you can see, one Party might have many addresses.
    I can retrieve either an Address or Party from the database using something like:
    em.createNamedQuery("Party.findById")
       .setParameter("id", 1)
       .getSingleResult();When I try to return it, I get a stackOverflowError in the server log. I'm using the default Toplink provider so enabling full logging on this, I can see the SQL.
    When retrieving an address, it selects all of the address fields and correctly binds the supplied Id value. It then performs a select on the Party table using the Address.Party value. This in turn causes it to attempt to retrieve an Address. After three queries, the error is thrown.
    I can't see why the above schema should cause this problem. Where an Address is requested, I would expect it to retrieve the address fields, including the value of the Party field but not the Party object itself. On the other hand. when a Party is retrieved, I would expect it to recurse through and return a collection of Address objects.
    Have I misunderstood this or am I missing some fundamental point about JAX-WS?
    Thanks for your help,
    -Phil

    You have to set both sides of the relations...
    for example to do this in a more seamless manner:
    public UserProfile
         public void addLog (UserActivityLog activity)
              logs.add (activity);
              if (!equals (activity.getUserProfile ()))
                   activity.setUserProfile (this);
    Now this is the most primitive of ways to maintain two sided relations.
    There are a lot of other patterns to get around this.
    If you want to set the UserActivityLog to a specific UserProfile without
    having a firm reference to ther UserProfile, you should get the object
    from the database/persistenceManager... as you are using application
    identity, you can do something like pm.getObjectById.
    JDO does not do magic references. If you set something to null, it will
    remain null until you set it.
    Srini wrote:
    Hi Guys
    I am trying to create a one to many relationship between 2 JDOs.
    UserProfile - User JDO having user info
    UserActivityLog - JDO having user log info
    UserProfile -- UserActivityLog
    1 many
    UserProfile - has a collection of UserActivityLog objects
    UserActivityLog - has a reference to UserProfile
    Qn 1:
    I created a UserProfile along with a collection of 2 UserActivityLog
    objects.
    Navigation:
    Now given a UserProfile object,i am able to get the UserActivityLog objects.
    But given a UserActivityLog object ,i get a NULL UserProfile object.
    Issues:
    Why this is happening???Do i need to set the reference for "UserProfile" in
    UserActivityLog before inserting???
    If so,then how do i add a UserActivityLog to an existing
    UserProfile???cos,if i create a UserActivityLog with reference to
    UserProfile ,then it will throw a Duplicate Key violation for UserProfile as
    it is already persisted in DB.
    It will be great if you can direct me to some one to many relationship
    examples already implemented.
    Thanks
    Srini
    Stephen Kim
    [email protected]
    SolarMetric, Inc.
    http://www.solarmetric.com

  • One-to-many relationship: problem with several tables on the one side...

    Hello
    I'm having problems developing a database for a content management system. Apart from details, I've got one main table, that holds the tree structure of the content ("resources") and several other tables that contain data of a particular datatype ("documents", "images", etc.). Now, there's one-to-many relationship between "resources" table and all the datatype tables - that is, in the "resources" table there's "resource_id" column, being a foreign key referenced to the "id" columns in the datatype tables.
    The problem is that this design is deficient. I can't tell form the "resource_id" column from which datatype table to get the data. It seems to me that one-to-many relationship only works with two tables. If the data on the one side of the relationship is contained in several tables, problems arise.
    Anybody knows a solution? I would be obliged.
    Regards
    Havocado

    Hi;
    A simple way may be create a view on referenced tables:
    Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0
    Connected as hr
    SQL>
    SQL> drop table resources;
    Table dropped
    SQL> create table resources(id number, name varchar2(12));
    Table created
    SQL> insert into resources values(1,'Doc....');
    1 row inserted
    SQL> insert into resources values(2,'Img....');
    1 row inserted
    SQL> drop table documents;
    Table dropped
    SQL> create table documents(id number, resource_id number,type varchar2(12));
    Table created
    SQL> insert into documents values(1,1,'txt');
    1 row inserted
    SQL> drop table images;
    Table dropped
    SQL> create table images(id number, resource_id number,path varchar2(24));
    Table created
    SQL> insert into images values(1,2,'/data01/images/img01.jpg');
    1 row inserted
    SQL> create or replace view vw_resource_ref as
      2    select id, resource_id, type, null as path from documents
      3      union
      4     select id, resource_id, null as type, path from images;
    View created
    SQL> select * from resources r inner join vw_resource_ref rv on r.id = rv.resource_id;
            ID NAME                 ID RESOURCE_ID TYPE         PATH
             1 Doc....               1           1 txt         
             2 Img....               1           2              /data01/images/img01.jpg
    SQL> Regards....

  • One to Many Relationship Issue

    Post Author: jmb1977
    CA Forum: Formula
    I am having a problem in which I have a one to many relationship with contact phone numbers and students. In other words, one student can have multiple contacts. (I work for a school district)
    I made up two formulas...called Contact1Phone and Contact2Phone.
    Here is the code I use to display the data:
    IF {STUDCTCT.CNTNUMBER} in &#91;"C1"&#93; THEN STDUCTCT.CNTWPHONE
    Then the other formula does the same, except uses "C2".
    What I get is either C1 or C2 displays, but never both for the same student. Anyway to make this work? Any help on this would be greatly appreciated!

    Post Author: jmb1977
    CA Forum: Formula
    I forgot to add, I do know that placing STUDCTCT.CNTNUMBER in &#91;C1,C2&#93; as a selection then just simply place the CNTWPHONE field into the details section of the report will give me the results. But the reason why I am trying it the other way is that I can export the data as one record per student, thus I am trying to put the fields and formulas into the group section.

  • One-to-many relationships problem

    Hi,
    I'm having some problems with one-to-many relationships.
    I've a two way relationship beetwen Person and Document.
    Person has a collection of Documents (1-n).
    Document has an instance for Person.
    In my database schema Document has a FK for person.
    The problem occurs when I'm trying to save the Person object
    with a collection of Documents.
    Oracle gives me the following message:
    ORA-00001: unique constraint (SMS.PK_PERSON) violated
    In my kodo.properties file I put:
    kodo.jdbc.ForeignKeyConstraints: true
    It seems that when the collection of Documents is persisted, kodo tries to
    save a new Person object for each Document.
    When I have just one instance of Document in my collection kodo persists
    it ok, but when I have move instances I get
    that problem.
    Can somebody help me?
    Thanks in advance,
    Joan Caffee

    You need to make sure each Document references the same Person object in
    the JVM. JDO persists your object model as-is. Each distinct JVM
    object becomes a distinct database record. You can't have multiple JVM
    objects in the same PersistenceManager representing the same database
    record.

  • One to many relationships in EJB

    I have two EBs related by a one to many relationship. The first of these tables is called Student and has studentId as its key. The second of the tables has a composite key made up of studentID, courseID and semesterID.
    However, when the tables are generated in NetBeans 5.5, I find that the Course table has studentID as both a primary key and a foreign key.
    I am at a loss to understand this as I am new to NetBeans and EJB.
    Can anyone advise?
    Thanks
    Martin O'Shea.
    The Student class:
    package CBSD_CW;
    import java.io.Serializable;
    import javax.persistence.*;
    import java.util.*;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    @Entity
    public class Student_EB implements Serializable {
        // Table columns.
        @Id
        @Column(name = "STUDENT_ID", nullable = false)
        private Long studentId; // Student ID. Entity <Student><ID> from file: SampleData.xml.
        @Column(name = "FIRST_NAME", length = 50, nullable = true)
        private String firstName; // First Name. Entity <Student><FirstName> from file: SampleData.xml.
        @Column(name = "LAST_NAME", length = 50, nullable = true)
        private String lastName; // Last Name. Entity <Student><LastName> from file: SampleData.xml.
        @Column(name = "STUDENT_LEVEL", length = 2, nullable = true)
        private String studentLevel; // Student Level. Entity <Student><Level> from file: SampleData.xml.
        @Column(name = "PROGRAM_NAME", length = 50, nullable = true)
        private String programName; // Program Name. Entity <Student><ProgramName> from file: SampleData.xml.
        @Column(name = "PROGRAM_NUMBER", length = 3, nullable = true)
        private String programNumber; // Program Number. Entity <Student><ProgramNumber> from file: SampleData.xml.
        // 1:M relationship with Course_EB.
        @OneToMany(cascade=CascadeType.ALL, mappedBy="student")
        private List<Course_EB> courses;
        public List<Course_EB> getCourses() {
           return courses;
        public void setCourses(List<Course_EB> courses) {
           this.courses = courses;
        // Accessors and mutators.
        public Long getId() {
            return this.studentId;
        public void setId(Long studentId) {
            this.studentId = studentId;
        public String getFirstName() {
            return firstName;
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        public String getLastName() {
            return lastName;
        public void setLastName(String lastName) {
            this.lastName = lastName;
        public String getStudentLevel() {
            return studentLevel;
        public void setStudentLevel(String studentLevel) {
            this.studentLevel = studentLevel;
        public String getProgramName() {
            return programName;
        public void setProgramName(String programName) {
            this.programName = programName;
        public String getProgramNumber() {
            return programNumber;
        public void setProgramNumber(String programNumber) {
            this.programNumber = programNumber;
        // Other methods.
        public boolean equals(Object obj) {
           if (obj == this) {
               return (true);
           if (!(obj instanceof Student_EB)) {
               return (false);
           if (obj == null) {
               return (false);
           Student_EB student = (Student_EB) obj;
           return (student.studentId == studentId);
    The Course class:
    package CBSD_CW;
    import javax.persistence.CascadeType;
    import javax.persistence.EmbeddedId;
    import javax.persistence.Entity;
    import javax.persistence.JoinColumn;
    import javax.persistence.JoinTable;
    import javax.persistence.ManyToOne;
    @Entity
    public class Course_EB implements java.io.Serializable {
       Course_PK course;
       // M:1 relationship with Student_EB.
       private Student_EB student;
       @ManyToOne(cascade=CascadeType.ALL)
       @JoinTable(name = "Student_EB", joinColumns= @JoinColumn(name = "STUDENT_ID", referencedColumnName = "studentId"))
       public Student_EB getStudent() {
          return (student);
       public void setStudent(Student_EB student) {
          this.student = student;
       // Constructor.
       public Course_EB() {
       // Accessors and mutators.
       @EmbeddedId
       public Course_PK  getCourse_PK () {
          return (course);
       public void setCourse_PK(Course_PK course) {
          this.course = course;
    The Course_PK class:
    package CBSD_CW;
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
    @Embeddable
    public class Course_PK implements java.io.Serializable {
       // Table columns.
       @Column(name = "STUDENT_ID", length = 4, nullable = false)
       private long studentId; // Student ID. Entity <Student><ID> from file: SampleData.xml.
       @Column(name = "COURSE_ID", length = 4, nullable = false) 
       private String courseId; // Course ID. Entity <Student><Course><Number> from file: SampleData.xml.
       @Column(name = "SEMESTER_CODE", length = 3, nullable = false)
       private String semesterCode; // Semester Code. Entity <Student><Course><SemesterCode> from file: SampleData.xml.
       @Column(name = "GRADE", nullable = true)
       private char grade; // Grade. Entity <Student><Course><Grade> from file: SampleData.xml.
       // Constructors.
       public Course_PK() {
       public Course_PK(long studentId, long courseid, String semesterCode) {
          this.studentId = studentId;
          this.courseId = courseId;
          this.semesterCode = semesterCode;
       // Accessors and mutators.
       public long getStudentId() {
          return (studentId);
       public void setStudentId(long studentId) {
          this.studentId = studentId;
       public String getCourseId() {
           return (courseId);
       public void setId(String courseId) {
           this.courseId = courseId;
       public String getSemesterCode() {
           return (semesterCode);
       public void setSemesterCode(String semesterCode) {
           this.semesterCode = semesterCode;
       public char getGrade() {
           return (grade);
       public void setGrade(char grade) {
           this.grade = grade;
       // Other methods.
       public boolean equals(Object obj) {
           if (obj == this) {
               return (true);
           if (!(obj instanceof Course_PK)) {
               return (false);
           if (obj == null) {
               return (false);
           Course_PK course = (Course_PK) obj;
           return ((course.studentId == studentId) &&
                   (course.courseId.equals(courseId)) &&
                   (course.semesterCode.equals(semesterCode)) &&
                   (course.grade == grade));
    }

    Because you have field
    @Column(name = "STUDENT_ID", length = 4, nullable = false)
       private long studentId; // Student ID. Entity <Student><ID> from file: SampleData.xml.In you Course_PK class. As a primary keys.
    An again you are joining it in field
        @ManyToOne(cascade=CascadeType.ALL)
       @JoinTable(name = "Student_EB", joinColumns= @JoinColumn(name = "STUDENT_ID", referencedColumnName = "studentId"))So it is appearing both inPrimary Key and in Foreign Key.

  • Need help mapping one-to-many relationship

    [Sorry, inadvertently cross-posted]
    Hello,
    I have a one-to-many mapping question that's probably a no-brainer for the
    experts of the group out there. My problem is that I can't get a collection
    of Items for a given Theme to be populated and I don't know if it's a
    problem in my system.jdo or in my classes (or both). For example, for Theme
    10,
    I want a collection of two Items, item_ids 1 and 2.
    I have db tables named ITEM and THEME with the following layouts:
    ITEM
    |==========================================================|
    | item_id(pk) | item_name | item_number | theme_id(fk) |
    |==========================================================|
    | 1 | This is Item1 | 1234 | 10 |
    | 2 | This is Item2 | 2954 | 10 |
    | 3 | This is Item3 | 2094 | 17 |
    | 4 | This is Item4 | 946 | 11 |
    | ... |
    |==========================================================|
    THEME
    |=======================================|
    | theme_id(pk) | theme_description |
    |=======================================|
    | 4 | Space |
    | 10 | Town |
    | 11 | Train |
    | 17 | Pirate |
    | ... |
    |=======================================|
    I have two PersistenceCapable classes that map to the above tables:
    package com.lego.data;
    public class Item
    public int item_id;
    private String item_number;
    private String item_name;
    private int theme_id;
    public Theme theme;
    public String toString()
    return
    item_number+":"+item_name+":"+theme.getCode()+":"+theme.getDescription();
    package com.lego.data;
    import java.util.*;
    public class Theme
    public int theme_id;
    public String theme_description;
    public Collection items;
    public String toString()
    return theme_id+":"+theme_description;
    and here is my system.jdo file:
    <?xml version = "1.0" encoding = "US-ASCII"?>
    <jdo>
    <package name="com.lego.data">
    <class name="Item" identity-type="application"
    objectid-class="com.lego.data.IntOId">
    <extension vendor-name="kodo" key="table" value="item"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="item_id" primary-key="true">
    <extension vendor-name="kodo" key="data-column" value="item_id"/>
    </field>
    <field name="item_number">
    <extension vendor-name="kodo" key="data-column" value="item_number"/>
    </field>
    <field name="item_name">
    <extension vendor-name="kodo" key="data-column" value="item_name"/>
    </field>
    <field name="theme_id">
    <extension vendor-name="kodo" key="data-column" value="theme_id"/>
    </field>
    <field name="theme">
    <extension vendor-name="kodo" key="theme_id-data-column"
    value="theme_id"/>
    </field>
    </class>
    <class name="Theme" identity-type="application"
    objectid-class="com.lego.data.ThemeKey">
    <extension vendor-name="kodo" key="table" value="theme"/>
    <extension vendor-name="kodo" key="lock-column" value="none"/>
    <extension vendor-name="kodo" key="class-column" value="none"/>
    <field name="theme_id" primary-key="true">
    <extension vendor-name="kodo" key="data-column" value="theme_id"/>
    </field>
    <field name="theme_description">
    <extension vendor-name="kodo" key="data-column"
    value="theme_description"/>
    </field>
    <field name="items">
    <collection element-type="Item"/>
    <extension vendor-name="kodo" key="inverse" value="theme"/>
    </field>
    </class>
    </package>
    </jdo>
    Thanks in advance for the help.
    -Tim

    Abe White wrote:
    The first thing to check is that you are always setting the "theme" field in
    your Items. If you add an Item i to the "themes" collection of a Theme t, but
    forget to also set i's "theme" field to t, then the change will never get
    written to the database.
    Next, make sure that whenever you set the "theme" field of an Item, you also
    set
    its "theme_id" field. You map both of these fields to the same column, so you
    better be sure they stay in synch.
    On a related note, you might try making the "theme_id" field non-persistent if
    things still aren't working for you. Mapping two fields to the same column
    might be causing trouble. It would be safer to make theme_id non-persistent
    anyway, and to always grab the id from the Theme stored in your "theme"
    field.
    Better OO programming and all that, though I can see that you might have
    performance issues in mind when doing it your way.
    Anyway, if you find that it works when you make theme_id nonpersistent, let us
    know and we'll see why the double-mapping of the column is causing problems,
    and hopefully find a fix.Abe,
    Thanks for the response but I'm still confused. I failed to mention that
    the Item and Theme tables are in an existing schema, so as you saw in my
    system.jdo, I am specifying application identity.
    Since this is an existing schema, the Item table has theme_id as the
    foreign key to the Theme table. So are saying that it is a problem to map
    the both theme_id as a data column and a Theme object in the Item at the
    same time?
    I guess what I don't understand is exactly what my system.jdo should look
    like to map a one-to-many relationship. In my case, from Theme (1) to Item
    (many). (See my system.jdo in previous post).
    Thanks
    -Tim

  • Using data from one-to-many relationship

    Hi,
    i have an one-to-many relationship among two tables similar to the structure as in the below reference:-
    [One-to-many-reference|http://docs.oracle.com/cd/E23507_01/Platform.20073/RepositoryGuide/html/s1204repositoryexamplefonetomanymappi01.html]
    taking this as an example, i have the city's name with me. using this data in the addr_tbl in the 'address' item-descriptor, i need to get the value of the 'name' in the usr_tbl in the 'user' item descriptor. i will have the list of 'city' with me which i have to iterate and display the corresponding 'name'.
    will i be able to perform this in the jsp itself or does it have to be done in java? a sample code snippet or reference for doing this will be of much help.
    thank you.

    Thanks a lot, Sheik.
    if i have to do the reverse, ie for the 'name' in the usr_tbl of user item-descriptor i have to fetch the 'city' values in the addr_tbl, will it suffice if i do the following?
    <dsp:droplet name="/atg/dynamo/droplet/RQLQueryForEach">
    <dsp:param name="queryRQL" value="name=\"sirius\""/>
    <dsp:param name="repository"
    value="/com/MyRepository"/>
    <dsp:param name="itemDescriptor" value="user"/>
    <dsp:oparam name="output">
    <dsp:valueof param="element.address.city"/>
    </dsp:oparam>
    </dsp:droplet>

Maybe you are looking for