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.

Similar Messages

  • 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....

  • Aggregate one-to-many relationship problem

    Hello,
    After migrating from Toplink 9i I've stumbled across a problem with our aggregate objects.
    Toplink Workbench reports no errors and generates a nice XML but in runtime I get this error whenever a aggregate function is used.
    [TopLink fin]: 2008.02.13 03:18:11.552--ServerSession(12626425)--Connection(29948747)--Thread(Thread[main,5,main])--SELECT DISTINCT t0.NPL_PACK_ID, t0.NPL_ID FROM NPL_MEDPROD t3, FASS_MEDPROD t2, NPL_MEDPROD t1, NPL_PACKAGE t0 WHERE (((t0.NPL_ID = t1._Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test) AND ((t1.NPL_ID = t2.NPL_ID) AND (t3.NPL_ID LIKE '19750613000031%'))) AND (t3.NPL_ID = t2.NPL_ID))
    Caused by: Undantag [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)): oracle.toplink.exceptions.DatabaseException
    Internt undantag: java.sql.SQLException: ORA-00911: invalid character
    Felkod: 911
    I belive that problem resides in this clause :
    t1._Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test
    I've created a small test project with just a couple of classes but the same aggregate problem occurs which has let me to believe the problem does not come from the migrating process which was my first guess. If anyone could help me discover what I am doing wrong it would be very appreciated. Below is my test project output.
    <?xml version="1.0" encoding="UTF-8"?>
    <toplink:object-persistence version="Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)" xmlns:opm="http://xmlns.oracle.com/ias/xsds/opm" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:toplink="http://xmlns.oracle.com/ias/xsds/toplink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <opm:name>test</opm:name>
    <opm:class-mapping-descriptors>
    <opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
    <opm:class>se.lif.fass.fassdata.impl.FASSMedProdImpl</opm:class>
    <opm:alias>FASSMedProdImpl</opm:alias>
    <opm:primary-key>
    <opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:primary-key>
    <opm:events xsi:type="toplink:event-policy"/>
    <opm:querying xsi:type="toplink:query-policy"/>
    <opm:attribute-mappings>
    <opm:attribute-mapping xsi:type="toplink:one-to-one-mapping">
    <opm:attribute-name>_Medprod</opm:attribute-name>
    <opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl</opm:reference-class>
    <opm:private-owned>true</opm:private-owned>
    <opm:foreign-key>
    <opm:field-reference>
    <opm:source-field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    <opm:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:field-reference>
    </opm:foreign-key>
    <opm:foreign-key-fields>
    <opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:foreign-key-fields>
    <toplink:batch-reading>true</toplink:batch-reading>
    <toplink:selection-query xsi:type="toplink:read-object-query"/>
    </opm:attribute-mapping>
    <opm:attribute-mapping xsi:type="toplink:direct-mapping">
    <opm:attribute-name>id</opm:attribute-name>
    <opm:read-only>true</opm:read-only>
    <opm:field table="FASS_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:attribute-mapping>
    </opm:attribute-mappings>
    <toplink:descriptor-type>independent</toplink:descriptor-type>
    <toplink:instantiation/>
    <toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
    <toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
    <toplink:tables>
    <toplink:table name="FASS_MEDPROD"/>
    </toplink:tables>
    </opm:class-mapping-descriptor>
    <opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
    <opm:class>schemas_npl.instance.impl.MedprodTypeImpl</opm:class>
    <opm:alias>MedprodTypeImpl</opm:alias>
    <opm:primary-key>
    <opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:primary-key>
    <opm:events xsi:type="toplink:event-policy"/>
    <opm:querying xsi:type="toplink:query-policy"/>
    <opm:attribute-mappings>
    <opm:attribute-mapping xsi:type="toplink:aggregate-object-mapping">
    <opm:attribute-name>_Medprodpack</opm:attribute-name>
    <toplink:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl</toplink:reference-class>
    <toplink:allow-null>false</toplink:allow-null>
    <toplink:field-translations>
    <toplink:field-translation>
    <toplink:source-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
    <toplink:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </toplink:field-translation>
    </toplink:field-translations>
    </opm:attribute-mapping>
    <opm:attribute-mapping xsi:type="toplink:direct-mapping">
    <opm:attribute-name>_Nplid</opm:attribute-name>
    <opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:attribute-mapping>
    <opm:attribute-mapping xsi:type="toplink:direct-mapping">
    <opm:attribute-name>id</opm:attribute-name>
    <opm:read-only>true</opm:read-only>
    <opm:field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:attribute-mapping>
    </opm:attribute-mappings>
    <toplink:descriptor-type>independent</toplink:descriptor-type>
    <toplink:instantiation/>
    <toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
    <toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
    <toplink:tables>
    <toplink:table name="NPL_MEDPROD"/>
    </toplink:tables>
    </opm:class-mapping-descriptor>
    <opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
    <opm:class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl</opm:class>
    <opm:alias>MedprodTypeImpl$MedprodpackTypeImpl</opm:alias>
    <opm:events xsi:type="toplink:event-policy"/>
    <opm:querying xsi:type="toplink:query-policy"/>
    <opm:attribute-mappings>
    <opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
    <opm:attribute-name>_Presentation</opm:attribute-name>
    <opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:reference-class>
    <opm:private-owned>true</opm:private-owned>
    <opm:target-foreign-key>
    <opm:field-reference>
    <opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
    <opm:target-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
    </opm:field-reference>
    </opm:target-foreign-key>
    <toplink:batch-reading>true</toplink:batch-reading>
    <toplink:container xsi:type="toplink:list-container-policy">
    <toplink:collection-type>com.sun.xml.bind.util.ListImpl</toplink:collection-type>
    </toplink:container>
    <toplink:selection-query xsi:type="toplink:read-all-query">
    <toplink:container xsi:type="toplink:list-container-policy">
    <toplink:collection-type>com.sun.xml.bind.util.ListImpl</toplink:collection-type>
    </toplink:container>
    </toplink:selection-query>
    </opm:attribute-mapping>
    </opm:attribute-mappings>
    <toplink:descriptor-type>aggregate</toplink:descriptor-type>
    <toplink:instantiation/>
    <toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
    <toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
    </opm:class-mapping-descriptor>
    <opm:class-mapping-descriptor xsi:type="toplink:relational-class-mapping-descriptor">
    <opm:class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:class>
    <opm:alias>MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:alias>
    <opm:primary-key>
    <opm:field table="NPL_PACKAGE" name="NPL_PACK_ID" xsi:type="opm:column"/>
    </opm:primary-key>
    <opm:events xsi:type="toplink:event-policy"/>
    <opm:querying xsi:type="toplink:query-policy"/>
    <opm:attribute-mappings>
    <opm:attribute-mapping xsi:type="toplink:direct-mapping">
    <opm:attribute-name>_Nplpackid</opm:attribute-name>
    <opm:field table="NPL_PACKAGE" name="NPL_PACK_ID" xsi:type="opm:column"/>
    </opm:attribute-mapping>
    <opm:attribute-mapping xsi:type="toplink:one-to-one-mapping">
    <opm:attribute-name>backref</opm:attribute-name>
    <opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl</opm:reference-class>
    <opm:foreign-key>
    <opm:field-reference>
    <opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
    <opm:target-field table="NPL_MEDPROD" name="NPL_ID" xsi:type="opm:column"/>
    </opm:field-reference>
    </opm:foreign-key>
    <opm:foreign-key-fields>
    <opm:field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
    </opm:foreign-key-fields>
    <toplink:indirection xsi:type="toplink:value-holder-indirection-policy"/>
    <toplink:selection-query xsi:type="toplink:read-object-query"/>
    </opm:attribute-mapping>
    <opm:attribute-mapping xsi:type="toplink:direct-mapping">
    <opm:attribute-name>id</opm:attribute-name>
    <opm:read-only>true</opm:read-only>
    <opm:field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
    </opm:attribute-mapping>
    </opm:attribute-mappings>
    <toplink:descriptor-type>independent</toplink:descriptor-type>
    <toplink:instantiation/>
    <toplink:copying xsi:type="toplink:instantiation-copy-policy"/>
    <toplink:change-policy xsi:type="toplink:deferred-detection-change-policy"/>
    <toplink:tables>
    <toplink:table name="NPL_PACKAGE"/>
    </toplink:tables>
    </opm:class-mapping-descriptor>
    </opm:class-mapping-descriptors>
    <toplink:login xsi:type="toplink:database-login">
    <toplink:platform-class>oracle.toplink.platform.database.oracle.Oracle8Platform</toplink:platform-class>
    <toplink:user-name>fassadmin</toplink:user-name>
    <toplink:password>3CC3773C96563CA0C89634305615359CD62D1A19DF561D1E</toplink:password>
    <toplink:driver-class>oracle.jdbc.driver.OracleDriver</toplink:driver-class>
    <toplink:connection-url>jdbc:oracle:oci8:@DB2</toplink:connection-url>
    </toplink:login>
    </toplink:object-persistence>
    Regards
    /Jonas

    The issue is in the one-to-many mapping in the aggregate,
    <br>
    <opm:attribute-mapping xsi:type="toplink:one-to-many-mapping">
      <opm:attribute-name>_Presentation</opm:attribute-name>
      <opm:reference-class>schemas_npl.instance.impl.MedprodTypeImpl$MedprodpackTypeImpl$PresentationTypeImpl</opm:reference-class>
      <opm:private-owned>true</opm:private-owned>
      <opm:target-foreign-key>
        <opm:field-reference>
          <opm:source-field table="NPL_PACKAGE" name="NPL_ID" xsi:type="opm:column"/>
          <opm:target-field name="_Presentation->NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test" xsi:type="opm:column"/>
        </opm:field-reference>
      </opm:target-foreign-key>There is an issue with the Mapping Workbench and shared aggregates with one-to-many mappings and translating the foreign key fields. Did this work before, I would be surprized if it did, unless the 2.5 Builder was used?
    Anyway the easiest workaround is to either edit the XML and change the NPL_ID_IN_REFERENCE_NPL_PACKAGE_NPL_MEDPROD_Test column name to what it should be, or define a descriptor amendment method to define the one-to-many mapping with the correct field names.
    -- James : EclipseLink

  • One-to-many graph problem

    Hi,
    I am haviing a crystal report problem. The problem relates to a one-to-many relationship involving two tables.
    I have a similar setup to the following:
    I have 2 database tables: table1 & table2
    table1 consists of 3 fields:
    {id#}, {yes/no},{up/down}
    table2 consists of 2 fields:
    {id#},
    the field can contain any of the following values: 'open', 'closed', 'final', 'complete'.
    The problem is that there exist many states to one id#.
    I have a bar graph in my report that displays a bar for the count of the{yes/no} field and a bar for the count of the {up/down} field. I want also a bar for the count of when the field = 'final'.
    What happens when I write a formula for the field in the second table and place it in the 'show values' section of the chart expert, is the count displayed in each bar on the graph increases significantly. I am assuming this is because there are multiple records in table 2 for each record in table 1.
    What I want to happen is that the graph displays bar 1 and bar 2 correctly and then when I put in the formula for the third bar, it simply displays that bar with the count for when the field = 'final'. I dont want it to affect the whole garph.
    Has anyone got any suggestions on how I can do this?
    I have tried messing around with the distinct records setting in crystal and also by writing an sql query specifying DISTINCT keyword instead of using the select expert, but to no avail.
    Please please can someone help me with this issue.
    Thank you.
    J

    You can add a 1-1 query key through the code API in a descriptor amendment method. You could also define a selection criteria on the 1-m mapping to filter the type=2.
    Example: (see Foundation Library manual 8-17)
    OneToOneQueryKey queryKey = new OneToOneQueryKey();
    queryKey.setName("organization");
    queryKey.setReferenceClass(Organization.class);
    ExpressionBuilder builder = new ExpressionBuilder();
    queryKey.setJoinCriteria(builder.getField("ORGANIZATION.ORG_ID").equal(builder.getParameter("RELATIONSHIP.PARENT_ID").and(builder.getParamater("RELATIONSHIP.RELATIONSHIP_TYPE").equal(2)));
    relationDescriptor.addQueryKey(queryKey);
    Example: (of 1-m mapping with selection criteria)
    OneToManyMapping mapping = new OneToManyMapping();
    mapping.setReferenceClass(Relation.class);
    mapping.setTargetForeignKey("RELATION.PARENT_ID");
    ExpressionBuilder builder = new ExpressionBuilder();
    mapping.setSelectionCriteria(builder.getField("RELATIONSHIP.PARENT_ID").equal(builder.getParameter("ORGANIZATION.ORG_ID").and(builder.getField("RELATIONSHIP.RELATIONSHIP_TYPE").equal(2)));
    orgDescriptor.addMapping(mapping);

  • 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.

  • One to many mapping problem

    In my JPA project I'm using these three classes:
    Cart.java:
    package com.spinnaker.pedja;
    import java.sql.Date;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.*;
    @Entity(name = "Cart")
    @Table(schema = "shop")
    public class Cart {
         @Id
         @Column(name = "cart_id")
         private int Cart_id;
         @Column(name = "cart_date")
         private Date date;
          @OneToMany(mappedBy = "cartItemPK", targetEntity = CartItemPK.class)
          private Set cartitemCollection = new HashSet(0);
         @ManyToOne
         @JoinColumn(name = "customer_id")
         private Customer customer;
         public Customer getCustomer() {
              return customer;
         public void setCustomer(Customer customer) {
              this.customer = customer;
         public Cart() {
          public Set getCartitemCollection() {
          return cartitemCollection;
          public void setCartitemCollection(Set cartitemCollection) {
          this.cartitemCollection = cartitemCollection;
         public int getCart_id() {
              return Cart_id;
         public void setCart_id(int cart_id) {
              this.Cart_id = cart_id;
         public Date getDate() {
              return date;
         public void setDate(Date date) {
              this.date = date;
    }, CartItem.java:
    package com.spinnaker.pedja;
    import java.io.Serializable;
    import javax.persistence.*;
    @Entity
    @Table(schema = "shop")
    public class CartItem implements Serializable {
         @EmbeddedId
         @ManyToOne
    //     @JoinColumn(name = "cart_id")
         CartItemPK cartItemPK;
         @Column(name = "quantity")
         private int quantity;
         @Column(name = "unit_price")
         private double unit_price;
    //     @JoinColumn(name = "cart_id")
    //     private Cart cart;
    //      public Cart getCart() {
    //      return cart;
    //      public void setCart(Cart cart) {
    //      this.cart = cart;
         public CartItem() {
         public CartItemPK getCartItemPK() {
              return cartItemPK;
         public void setCartItemPK(CartItemPK cartItemPK) {
              this.cartItemPK = cartItemPK;
         public int getQuantity() {
              return quantity;
         public void setQuantity(int quantity) {
              this.quantity = quantity;
         public double getUnit_price() {
              return unit_price;
         public void setUnit_price(double unit_price) {
              this.unit_price = unit_price;
    }and CartItemPK.java:
    package com.spinnaker.pedja;
    import java.io.Serializable;
    import javax.persistence.*;
    @Table(schema="shop")
    @Embeddable
    public class CartItemPK implements Serializable{
         @Column(name="item_id",nullable=false)
         private int itemId;
    //     @ManyToOne
    //     @JoinColumn(name = "cart_id")
    //     private Cart cart;
         @Column(name="cart_id",nullable=false)
         private int cartId;
         public int getItemId() {
              return itemId;
         public void setItemId(int itemId) {
              this.itemId = itemId;
         public int getCartId() {
              return cartId;
         public void setCartId(int cartId) {
              this.cartId = cartId;
    I'm having problem with mapping one to many relationship between Cart and CartItem.I had to introduce CartItemPK class because CartItem has composite primary key.Help please!!!

    In my test class I'm using this code:
    Cart cart=em.find(Cart.class, 33);
              Set cartItems=cart.getCartitemCollection();
              for (Iterator iterator = cartItems.iterator(); iterator.hasNext();) {
                   CartItem cart_item = (CartItem) iterator.next();
                   System.out.println(cart_item.getCartItemPK().getCartId());
              }and this error happens:
    Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.spinnaker.pedja.Cart.cartitemCollection[com.spinnaker.pedja.CartItemPK]
         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:247)
         at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:159)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:95)
         at com.spinnaker.pedja.test.Test.main(Test.java:30)
    Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: com.spinnaker.pedja.Cart.cartitemCollection[com.spinnaker.pedja.CartItemPK]
         at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:979)
         at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:530)
         at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:471)
         at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:43)
         at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1136)
         at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296)
         at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
         at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
         at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
         ... 4 more
    I didn't find any example on the internet about my particular case.In the database,Cart and CartItem are conected via cart_id field.But in my JPA project,cart_id field is a part of a composite key CarItemPK.

  • 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 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 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 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 CMR problem

    I am trying to get Container Managed Relationships working with Oracle Application Server. I am sure that the problem it quite obvious to anyone who has got this working before, but after carefully following numerous examples, I still cant get them to work. I have various issues including the application server blocking when it calls the getB() method in "A" to populate the items from table "B", even though the generated SQL looks okay e.g., "select B_PK from B where (b_fk = 1)".
    I would be extremely grateful if you could point out my (hopefully obvious) mistake as I wrestled with it for the past couple of weeks.
    Any ideas?
    Cheers,
    Jonathan
    I have two tables A and B; A has a one-to-many relationship with B:
    Table A:
         A_PK          (primary key)
         A_NAME
    Table B:
         B_PK          (primary key)
         B_NAME
         B_FK          (foreign key to table A)
    My ejb-jar.xml file is:
    <ejb-jar>
    <enterprise-beans>
    <entity>
    <description>Entity Bean ( CMP )</description>
    <display-name>A</display-name>
    <ejb-name>A</ejb-name>
    <home>mypackage1.AHome</home>
    <remote>mypackage1.A</remote>
    <local-home>mypackage1.ALocalHome</local-home>
    <local>mypackage1.ALocal</local>
    <ejb-class>mypackage1.impl.ABean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>java.lang.Long</prim-key-class>
    <reentrant>False</reentrant>
    <cmp-version>2.x</cmp-version>
    <abstract-schema-name>A</abstract-schema-name>
    <cmp-field><field-name>a_pk</field-name></cmp-field>
    <cmp-field><field-name>a_name</field-name></cmp-field>
    <primkey-field>a_pk</primkey-field>
    </entity>
    <entity>
    <description>Entity Bean ( CMP )</description>
    <display-name>B</display-name>
    <ejb-name>B</ejb-name>
    <home>mypackage1.BHome</home>
    <remote>mypackage1.B</remote>
    <local-home>mypackage1.BLocalHome</local-home>
    <local>mypackage1.BLocal</local>
    <ejb-class>mypackage1.impl.BBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>java.lang.Long</prim-key-class>
    <reentrant>False</reentrant>
    <cmp-version>2.x</cmp-version>
    <abstract-schema-name>B</abstract-schema-name>
    <cmp-field><field-name>b_pk</field-name></cmp-field>
    <cmp-field><field-name>b_name</field-name></cmp-field>
    <cmp-field><field-name>b_fk</field-name></cmp-field>
    <primkey-field>b_pk</primkey-field>
    </entity>
    </enterprise-beans>
    <relationships>
    <ejb-relation>
    <ejb-relation-name>A-B</ejb-relation-name>
    <ejb-relationship-role>
    <multiplicity>One</multiplicity>
    <cascade-delete/>
    <relationship-role-source>
    <ejb-name>A</ejb-name>
    </relationship-role-source>
    <cmr-field>
    <cmr-field-name>b</cmr-field-name>
    <cmr-field-type>java.util.Collection</cmr-field-type>
    </cmr-field>
    </ejb-relationship-role>
    <ejb-relationship-role>
    <multiplicity>Many</multiplicity>
    <relationship-role-source>
    <ejb-name>B</ejb-name>
    </relationship-role-source>
    </ejb-relationship-role>
    </ejb-relation>
    </relationships>
    </ejb-jar>
    And my orion-ejb-jar.xml file is:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <!DOCTYPE orion-ejb-jar PUBLIC "-//Evermind//DTD Enterprise JavaBeans 1.1 runtime//EN" "http://xmlns.oracle.com/ias/dtds/orion-ejb-jar.dtd">
    <orion-ejb-jar>
    <enterprise-beans>
    <entity-deployment name="A" copy-by-value="false" data-source="jdbc/Connection1DS" exclusive-write-access="false" table="a">
    <primkey-mapping>
    <cmp-field-mapping name="a_pk" persistence-name="a_pk"
    persistence-type="int(11)"/>
    </primkey-mapping>
    <cmp-field-mapping name="a_pk" persistence-name="a_pk"
    persistence-type="int(11)"/>
    <cmp-field-mapping name="a_name" persistence-name="a_name"
    persistence-type="varchar(100)"/>
    <cmp-field-mapping name="b">
    <collection-mapping table="B">
    <primkey-mapping>
    <cmp-field-mapping name="b_fk" persistence-name="B_FK"/>
    </primkey-mapping>
    <value-mapping type="mypackage1.BLocal">
    <cmp-field-mapping>
    <entity-ref home="B">
    <cmp-field-mapping name="b_pk" persistence-name="B_PK"/>
    </entity-ref>
    </cmp-field-mapping>
    </value-mapping>
    </collection-mapping>
    </cmp-field-mapping>
    </entity-deployment>
    <entity-deployment name="B" copy-by-value="false" data-source="jdbc/Connection1DS" exclusive-write-access="false" table="b">
    <primkey-mapping>
    <cmp-field-mapping name="b_pk" persistence-name="b_pk"
    persistence-type="int(11)"/>
    </primkey-mapping>
    <cmp-field-mapping name="b_pk"
    persistence-name="b_pk" persistence-type="int(11)"/>
    <cmp-field-mapping name="b_fk" persistence-name="b_fk"
    persistence-type="int(11)"/>
    </entity-deployment>
    </enterprise-beans>
    <assembly-descriptor>
    <default-method-access>
    <security-role-mapping impliesAll="true" name="&lt;default-ejb-caller-role>"/>
    </default-method-access>
    </assembly-descriptor>
    </orion-ejb-jar>

    Ok, I found out something strange. If I do the addPet operation twice in the client the new relationship is created, too.
    p = home.create("Violetta");
    p.addNewPet("Jenny");
    p = home.create("Frank");
    p.addPet("Jenny");
    p.addPet("Jenny");
    May this be a timing problem? Or is there a command I could execute to ensure all data manipulation is populated to the DB. (Like close() in JDBC)
    TIA
    Frank

  • 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 question.

    Let's say we have table1 and table2
    Table1 has ID, and let's say Name for fields.
    Table2 has ID, and let's say SSN for fields.
    This is not so, but illustrates my points well.
    Table2 has many records with the same ID, who just happen to have the same SSN. That would usually be a logical conclusion.
    Table1 has only 1 of each ID in it. So you might say that ID is a foreign key in table2, except one problem. I don't think they know what primary keys are here, much less foreign keys.
    Anyway, I have to write a query where I get the ID from table1 and need the SSN from table2. That's the only place in this scenario that SSN is.
    My question is this - since this is a one to many relationship, yet I only need 1 result, how would I write this using the (+) way of notation? I am using 8i.
    Right now, I am doing something like this, using a DISTINCT:
    Select DISTINCT t1.ID, t1.Name, t2.SSN
    From table1, table2,
    Where t1.ID = t2.ID (+);
    First of all, is this the correct way of writing it?
    And second, I am wondering if, perchance for some error, there were 2 or more SSNs in table2, what would happen then? Would I get a too many rows error?
    And if so, how can I trap it and possibly get just the first occurrence of it?
    Is that even a sound way of doing it?
    Thanks for any thoughts here.

    You would need to turn your table2 into an in-line view in order to outer join to it properly. Minimally, something like:
    SELECT t1.id, t1.name, t2.ssn
    FROM table1 t1,
         (SELECT DISTINCT id, ssn
          FROM table2) t2
    WHERE t1.id = t2.id(+)If there may be multiple ssn in t2 for a single id, you will need to determine which one you want to keep and use something like:
    SELECT t1.id, t1.name, t2.ssn
    FROM table1 t1,
         (SELECT id, ssn
          FROM (SELECT id, ssn,
                       ROW_NUMBER() OVER (PARTITION BY id,
                                          ORDER BY column_that_makes_it_first) rn
                FROM table2)
          WHERE rn = 1) t2
    WHERE t1.id = t2.id(+)This should work on 8.1.7.4 Enterprise Edition. If you have a different version, then the analytic function may not work so you would need something more like:
    SELECT t1.id, t1.name, t2.ssn
    FROM table1 t1,
         (SELECT id, ssn
          FROM (SELECT id, ssn, rownum rn
                FROM (SELECT id, ssn,
                      FROM table2
                      ORDER BY id, column_that_makes_it_first))
          WHERE rn = 1) t2HTH
    John

  • 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

  • How Can realize a one-to-many relationship via RIA service in lightswitch

    I have to query a large data and the normal query in lightswitch is so slow that I decided to use RIA service to improve the query.However I am not very good at RIA service. I follow
    this tutorial and set up a very simple RIA service. In my project, I have a one-to-many relationship but I don't know how to
    realize it . here is the Relationship:
    public class CombinedStadium
    private EcoStatus _ecoStatus;
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
    public string Owner { get; set; }
    public string Street { get; set; }
    public string OrgCode { get; set; }
    public string Place { get; set; }
    public int? FoundYear { get; set; }
    public double? LandArea { get; set; }
    public double? BuildingArea { get; set; }
    public double? SiteArea { get; set; }
    public double? Investment { get; set; }
    public double? Fiscal { get; set; }
    public double? CommonWeal { get; set; }
    public double? SelfRaised { get; set; }
    public double? SocialDonate { get; set; }
    public double? Other { get; set; }
    public double? Longitude { get; set; }
    public double? Latitude { get; set; }
    public string Note { get; set; }
    public byte[] Photo { get; set; }
    [Include]
    [Association("Stadium_EcoStatus", "Id", "EcoId", IsForeignKey = false)]
    public virtual EcoStatus EcoStatus
    get { return this._ecoStatus; }
    set
    this._ecoStatus = value;
    if (value == null)
    this.Id = value.Id;
    I am not sure whether it is right or not. But I want "one CombinedStadium Entity may contains
    more than one(many)EcoStatus Entities.
    I tried the code above and update my datasource, I got the error "the entity
    LightSwitchApplication.Implementation.EcoStatus's property doesn't supported by the type of StadiumEcoReference".
    How Can I realize a one-to-many relationship via RIA and use it in my lightswitch program?
    thx !!!

    namespace WCF_RIA_Project
    public class CombinedStadium
    [Key]
    public int SiteId { get; set; }
    public string Name { get; set; }
    public string Category { get; set; }
    public string Owner { get; set; }
    public string Street { get; set; }
    public string OrgCode { get; set; }
    public string Place { get; set; }
    public int? FoundYear { get; set; }
    public double? LandArea { get; set; }
    public double? BuildingArea { get; set; }
    public double? SiteArea { get; set; }
    public double? Investment { get; set; }
    public double? Fiscal { get; set; }
    public double? CommonWeal { get; set; }
    public double? SelfRaised { get; set; }
    public double? SocialDonate { get; set; }
    public double? Other { get; set; }
    public double? Longitude { get; set; }
    public double? Latitude { get; set; }
    public string Note { get; set; }
    public byte[] Photo { get; set; }
    [Include]
    [Association("Stadium_EcoStatus", "SiteId", "StadiumId")]
    public IQueryable<CombindeEcoStatus> EcoStatus { get; set; }
    public class CombindeEcoStatus
    [Key]
    public int EcoId { get; set; }
    public string StatdiumName { get; set; }
    public int? StadiumId { get; set; }
    public int? Year { get; set; }
    public int? EmployeeNum { get; set; }
    public string OperateMode { get; set; }
    public string OpenStatus { get; set; }
    public double? OpeningDays { get; set; }
    public string ClientCount { get; set; }
    public double? Income { get; set; }
    public double? Expend { get; set; }
    [Include]
    [Association("Stadium_EcoStatus", "StadiumId", "SiteId", IsForeignKey = true)]
    public CombinedStadium Stadium
    get;
    set;
    public class WCF_RIA_Service : DomainService
    private ApplicationData m_context;
    public ApplicationData Context
    get
    if (this.m_context == null)
    string connString =
    System.Web.Configuration.WebConfigurationManager
    .ConnectionStrings["_IntrinsicData"].ConnectionString;
    EntityConnectionStringBuilder builder = new EntityConnectionStringBuilder();
    builder.Metadata =
    "res://*/ApplicationData.csdl|res://*/ApplicationData.ssdl|res://*/ApplicationData.msl";
    builder.Provider =
    "System.Data.SqlClient";
    builder.ProviderConnectionString = connString;
    this.m_context = new ApplicationData(builder.ConnectionString);
    return this.m_context;
    [Query(IsDefault = true)]
    public IQueryable<CombinedStadium> GetAllStadiums()
    var stadiumsQuery = from stadium in this.Context.StadiumSet
    select new
    ID = stadium.Id,
    Name = stadium.Name,
    Category = stadium.Category.Name,
    OwnerParts = stadium.Owner2StadiumMediatorCollection.Select(x => x.Owner.Name),
    Street = stadium.Street.Name,
    OrgCode = stadium.StadiumBase.OrgCode,
    Place = stadium.StadiumBase.Place,
    FoundYear = stadium.StadiumBase.FoundYear,
    LandArea = stadium.StadiumBase.LandArea,
    BuildingArea = stadium.StadiumBase.BuildingArea,
    SiteArea = stadium.StadiumBase.SiteArea,
    Investment = stadium.StadiumBase.Investment,
    Fiscal = stadium.StadiumBase.Fiscal,
    CommonWeal = stadium.StadiumBase.CommonWeal,
    SelfRaised = stadium.StadiumBase.SelfRaised,
    SocialDonate = stadium.StadiumBase.SocialDonate,
    Other = stadium.StadiumBase.Other,
    Longitude = stadium.StadiumBase.Longitude,
    Latitude = stadium.StadiumBase.Latitude,
    Note = stadium.StadiumBase.Note,
    Photo = stadium.StadiumBase.Photo,
    var result = stadiumsQuery.AsEnumerable().Select(x => new CombinedStadium()
    SiteId = x.ID,
    Name = x.Name,
    Category = x.Category,
    Owner = string.Join("/", x.OwnerParts),
    Street = x.Street,
    OrgCode = x.OrgCode,
    Place = x.Place,
    FoundYear = x.FoundYear,
    LandArea = x.LandArea,
    BuildingArea = x.BuildingArea,
    SiteArea = x.SiteArea,
    Investment = x.Investment,
    Fiscal = x.Fiscal,
    CommonWeal = x.CommonWeal,
    SelfRaised = x.SelfRaised,
    Other = x.Other,
    Longitude = x.Longitude,
    Latitude = x.Latitude,
    Note = x.Note,
    Photo = x.Photo,
    }).AsQueryable();
    return result;
    [Query(IsDefault = true)]
    public IQueryable<CombindeEcoStatus> GetAllEcoStatuses()
    var stadiumEco = from eco in this.Context.EcoStatusSet
    select new CombindeEcoStatus()
    EcoId = eco.Id,
    StatdiumName = eco.StadiumEco.Name,
    StadiumId = eco.StadiumEco.Id,
    Year = eco.Year,
    EmployeeNum = eco.Employee,
    OperateMode = eco.OperateMode,
    OpenStatus = eco.OpenStatus,
    OpeningDays = eco.OpeningDays,
    ClientCount = eco.ClientCount,
    Income = eco.Income,
    Expend = eco.Expend
    return stadiumEco;
    protected override int Count<T>(IQueryable<T> queryable)
    return queryable.Count();
    now I have solved my problem, but when I query the data in Lihgtswitch HTMLClient . I can't get the related entities "CombindeEcoStatus" . How can I write the return value of
    GetAllStadiums function to get the related CombindeEcoStatus of each
    CombinedStadium?
    thanks!

Maybe you are looking for

  • Reports can't be upgraded from 2005 to 2008

    I have converted all my rdl reports from 2005 to 2008 through BIDS conversion wizard.I have also converted the XSD file from 2005 to 2008. When I try to load the report locally(through dotnet code), I am getting below run time error. The report defin

  • Are Keywords etc. transferable from one computer to another?

    I'm working abroad at the moment using my laptop to manage my photos - usually at home I use another PC for my photography. If I organise my photos here by adding new keywords, ratings, metadata etc. are there any issues in transferring those criteri

  • How to change iPhoto default

    Is there a way you can change the default settings of slideshows. I always want the music and ken burns effect turned off in my slideshows. At the moment every time I create a new slideshow I have to manually change these settings.

  • Unable to continue because of a hardware or system error...

    ...Sorry, but this error is unrecoverable. Este problema me está matando...me sale aleatoriamente cada x tiempo sin razón aparente. No he tocado nada de configuración y ha aparecido de un día para otro al arrancar el PC. He desinstalado, reinstalado;

  • I want my old version(iOS 6.1.3) iOS 7 just a ****

    i want a revert back to my old ios....please help mee......i dont need ios7