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.

Similar Messages

  • 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 Mapping with different SQL types

    We have an interesting one to many relationship in our system in which the source and target field SQL types do not match, but the values do. The relationship is actually between multiple entries in the same database table. So, imagine we have some table that looks sort of like this:
    KEY ObjectID OwnerNo
    100 1234     0
    101 ABCD     1234
    102 EFGH     1234ObjectID is defined as a varchar type, but Parent entries are guaranteed to have integer value ObjectIDs. Child entries point to the parent through the OwnerNo field, which defined in the database as a numeric.
    A simple one-to-many mapping will give you the following SQL error on execution: [SQL0401] Comparison operator = operands not compatible.
    I tried modifying my descriptor after load as follows:
       public static void modifyOneToMany(Descriptor descriptor)
           ExpressionBuilder builder = new ExpressionBuilder();
           Expression exp = builder.getField("OwnerNo").
              equal(builder.getField("ObjectID").toNumber());
           descriptor.getMappingForAttributeName("children")
              .setSelectionCriteria(exp);
       }But this introduces two problems in the generated SQL ( ... WHERE ((t0.OwnerNo = TO_NUMBER(t0.ObjectID) ... ). First, this generates a where clause using the function TO_NUMBER, which is not supported by DB2 on AS400, our database platform. Second, the table reference is off in the generated SQL--I couldn't find a way to specify that the right hand side of the = operator should be from the parent of the one to many mapping--both sides are referenced from the child context (t0).

    I found the getFunction() method on Expression, so I can solve half of this problem with the following code:
       public static void modifyOneToMany(Descriptor descriptor)
         if (descriptor.getMappingForAttributeName("children").isOneToManyMapping())
           OneToManyMapping map = (OneToManyMapping) descriptor.
                                  getMappingForAttributeName("children");
           DatabaseField objectID= (DatabaseField) map.getSourceKeyFields().get(0);
           DatabaseField ownerNo = (DatabaseField) map.getTargetForeignKeyFields().get(0);
           ExpressionBuilder builder = new ExpressionBuilder();
           Expression exp = builder.getField(ownerNo).getFunction("CHAR").
                            equal(builder.getField(objectID));
           map.setSelectionCriteria(exp);
       }This generates the following where clause:
    ... WHERE ((CHAR(t0.OwnerNo) = t0.ObjectID) ...
    But, I still have two questions:
    1. How do we get the right hand side of this comparison to reference the Parent part of the 1-M mapping?
    2. Since character and numeric conversions are pretty standard SQL functions, is there something wrong with the DB2 database platform I'm using?

  • Key Method in one to many mapping

    I have problem in one to many mapping. I use a composite key and use get method of that key as Key Method, toplink seems not to realize this change, and can't acommodate that.
    any one had same problem?

    Could you explain in more detail what it is you are tyring to do? By 'Key Method' do you mean you are using a Map as the collection type of a OneToMany mapping? What do you mean by change? Are you changing the composit key?
    --Gordon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • One to many mapping

    Having trouble with the following poblem.. specially how to code getChildren??????? Help urgent
    Create a class called Families which creates a one-to-many mapping of parent name (String) to Child objects. Create any needed member variables and write the two specified methods. (You do not need to write the Child class.)
    class Families {
    public void addToFamily( String parent, Child child) {
    public List getChildren( String parent) {
    I have done the following..
    import java.util.ArrayList;
    import java.util.List;
    class Families {
    private String parentName;
    List <child> children = new ArrayList();
    public Families(String name){
    this.parentName = name;
    public void addToFamily( String parent, child kid) {
    Families f = new Families(parent);
         f.children.add(kid);      
    public List<child> getChildren( String parent) {
         return this.children;
    }

    Having trouble with the following poblem.. specially
    how to code getChildren??????? Help urgent
    Create a class called Families which creates a
    one-to-many mapping of parent name (String) to Child
    objects. Create any needed member variables and write
    the two specified methods. This key:
    (You do not need to write the Child class.)How can the following line possibly work?
    List <child> children = new ArrayList();It's not syntactically correct, AND you're not writing the Child class.
    %

  • Partial Attribute search on a one to many mapping

    Is it possible to include an attribute that is a one to many mapping as a partial attribute in a Read All Query?

    Is it possible to include an attribute that is a one to many mapping as a partial attribute in a Read All Query?

  • Setting criteria on one-to-many mapping

    Hello,
    A quick question. Let's say you have two tables, TABLE A and TABLE B. TABLE A- which has a one to many relationship with TABLE B.
    When I do a query to get an object from TABLE A, I also get back a collection of TABLE B objects. I'd like to be able to alway be able to restrict the TABLE B objects I get back by adding an additional criteria like "where TABLE_B.DRAFT = 'N'" so that I always only get back TABLE B objects that are not drafts. Is there anyway to add this to the DirectToField Mapping or anywhere else in the Toplink Project so that I don't have to specifically setup the query in my DAO code?
    Thanks in advance for any help,
    Mark

    This is a follow-on to the previous question. I've been asked to create a domain object, Member, that would have two relationships with the child table Rec (Recommendations), a one-to-one mapping with the only record in the Rec table that has is "approved", and a one-to-many mapping with all the records for the Member. I realize from the answer received above that putting criteria in a mapping isn't recommended, but did want to see if it was even doable in case it was needed. Unfortunately, I get this error below:
    "A non-read-only mapping must be defined for the sequence number field."
    Below are my relevant mappings. Any thoughts on this?
    Thanks,
    Mark
    OneToOneMapping approvedRecInfoMapping = new OneToOneMapping();
         approvedRecInfoMapping.setAttributeName("approvedRecInfo");
         approvedRecInfoMapping.setGetMethodName("getApprovedRecInfoHolder");
         approvedRecInfoMapping.setSetMethodName("setApprovedRecInfoHolder");
         approvedRecInfoMapping.setReferenceClass(domain.Rec.class);
         approvedRecInfoMapping.useBasicIndirection();
         approvedRecInfoMapping.readOnly();
         approvedRecInfoMapping.addForeignKeyFieldName("PROM_REC.PRM_ID", "PROM_REC_MEMBER.ID");
         approvedRecInfoMapping.setSelectionCriteria(new ExpressionBuilder().get("approved").equal("true"));
         descriptor.addMapping(approvedRecInfoMapping);
         OneToManyMapping publicRecsMapping = new OneToManyMapping();
         publicRecsMapping.setAttributeName("publicRecs");
         publicRecsMapping.setGetMethodName("getPublicRecs");
         publicRecsMapping.setSetMethodName("setPublicRecs");
         publicRecsMapping.setReferenceClass(domain.Rec.class);
         publicRecsMapping.useTransparentCollection();
         publicRecsMapping.readOnly();
         publicRecsMapping.useCollectionClass(oracle.toplink.indirection.IndirectList.class);
         publicRecsMapping.addTargetForeignKeyFieldName("REC.PRM_ID", "MEMBER.ID");
         descriptor.addMapping(publicRecsMapping);

  • 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);

  • One-to-many mapping and update the many part

    Hello !
    Here's my problem,
    I've got an object A having a vector of object B.
    The mapping in toplink is one-to-many with the back-references set in B.
    Insertion : no problem.
    Now i would like to change the Vector of B (inserting new B, updating existing B) in a function with the Vector vC (modified vector of B).
    What is the best way to do this ?
    I tried many thing but either I have toplink 6004 error, or doing it by removing all elements of the Vector (deleting all B in database), and then setting A with C (recreating all object in the modified Vector).
    Another way to explain my case:
    how to do this in UnitOfWork ?
    function modifyAVectorOfB(A, vectorOfC)
    AClone = uow.registerObject(A);
    Aclone.setVectorOfB(vectorOfC);
    uow.commit;
    (and in database all existing object in C are updated, new object in C are created, removed object in C are deleted)

    Have found a solution, read all object in the modified Vector, read the modified object in the Unit Of Work with readObject(B) (So i get the database or cache version) and then comparing it with the modified to change what is needed to be change.

  • 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

  • Insert with one-to-many mapping

    Hi,
    I've got the following situation:
    - an object A with a vector of object B
    - I defined a one-to-many relation in the descriptor of A referencing a collection of B using indirection through valueHolderInterface, the "private owned" is also checked
    - I defined a one-to-one relation in the descriptor of B referencing the object A using indirection through valueHolderInterface
    - the bidirectional relationship is maintained.
    I try to insert a new object A with a new object B inside. The code is as follows:
    A = new A();
    B = new B();
    // ... set the A attribute values
    // ... set the B attribute values
    A.addB(B);
    UnitOfWork uow = session.acquireUnitOfWork();
    uow.registerNewObject(A);
    uow.commit();
    where addB(b) is as follows:
    ((java.util.Vector)bvector.getValue()).add(b);
    b.setA(this);
    Executing this code, the object A is inserted in the database but the object B is not. And I would like that the object B is also stored in the database. Do I really have to register it? I want to make the insert in just one transaction. Have anyone an idea? I tried a lot of different configurations and just one SQL insert order is generated by Toplink.
    Thanks,
    Frédéric

    Hi Don,
    This is with reference to your comments on the following oracel forum query "http://forums.oracle.com/forums/thread.jspa?messageID=508819&#55728;&#57235;" regarding 1:M mapping insertion problem.(Same one)
    Actually I also have the same kind of scenario but the data in not getting inserted to the detail table. It always gives ORA-1400 error as it is unable to populate the foreign key of parent in child table.
    Can you suggest if I am missing something.
    Your quick response will be appreciated.
    Message was edited by:
    user466708

  • Inheritance and One-To-Many Mapping Issue

    Are there any known issues with TopLink 4.6 mapping a one-to-many relationship where the classes in the list span more than 2 levels deep in the inheritance chain? We seem to notice that TopLink creates the class that is 2 levels deep before the owning class.

    Sorry for the delayed response to your post. I'm not sure I follow what you mean by "owning class". You have a 1-M mapping where the M has inheritance. Are you mapping to the root of the inhertance hierarchy, or to a leaf class? I.e., do you have a 1-M "Company - Employee" or a 1-M "Company - SalariedEmployee". In this example, what would you call the "owning class"?
    - Don

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

    Hi all,
    I have a question regarding a one to many field mapping I'm using in a
    class.
    I have a class AImpl which implements A, and BImpl which implements B.
    class AImpl implements A
    Collection bs;
    class BImpl implements B
    A a;
    I've created an inverse mapping in the package.jdo file as such:
    <class name="AImpl">
    <field name="bs">
    <collection element-type="BImpl"/>
    <extension vendor-name="kodo" key="inverse-owner" value="a"/>
    </field>
    </class>
    I get an error when the mapping tool is run saying;
    Field "AImpl.bs" names field "a" as its inverse-owner, but a is not a
    field of the related type.
    When I change the BImpl class to have AImpl a, it works fine.
    I'm wondering is there a way to leave the interface in the BImpl class and
    somehow declaritively tell the mappingtool that the field is an AImpl, as
    this allows me to separate interface from implementation in a much more
    efficient way when I build my modules.
    Thanks,
    Brendan

    Thanks Stephen for your quick response.
    I added
    <field name="a">
    <extension vendor-name="kodo" key="type" value="AImpl"/>
    </field>
    and it worked.
    Brendan
    Stephen Kim wrote:
    You can explicitly declare field/element types to be of a certain type:>
    http://solarmetric.com/Software/Documentation/3.0.3/docs/ref_guide_meta_ext.html#type
    Brendan Brothers wrote:
    Hi all,
    I have a question regarding a one to many field mapping I'm using in a
    class.
    I have a class AImpl which implements A, and BImpl which implements B.
    class AImpl implements A
    Collection bs;
    class BImpl implements B
    A a;
    I've created an inverse mapping in the package.jdo file as such:
    <class name="AImpl">
    <field name="bs">
    <collection element-type="BImpl"/>
    <extension vendor-name="kodo" key="inverse-owner" value="a"/>
    </field>
    </class>
    I get an error when the mapping tool is run saying;
    Field "AImpl.bs" names field "a" as its inverse-owner, but a is not a
    field of the related type.
    When I change the BImpl class to have AImpl a, it works fine.
    I'm wondering is there a way to leave the interface in the BImpl class and
    somehow declaritively tell the mappingtool that the field is an AImpl, as
    this allows me to separate interface from implementation in a much more
    efficient way when I build my modules.
    Thanks,
    Brendan
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

Maybe you are looking for

  • Video No longer plays

    I recently added a new season of shows on my IPOD. My computer crashed during the transfer but the shows still show up on my machine and the Ipod. However, when watching the shows my Ipod would show a black screen and that it was playing. There would

  • How do i create this kind of click box?? HELP

    Hi There, How do i create a click box that when you double click it a black dot is displayed. Im sorry if im not being clear. I mean a dot in the middle of a circular click box. When you click multiple choice, sort of. Any help would be appreciated!

  • Data Migration from SQL server best option

    Hi all, I am importing data from SQL server to oracle server, both of them are on different machines. I had suggested DTS to be most viable option to do so, the SQL server team needs to know why DTS, here are the other options that i am aware of 1) F

  • Standard report S_ALR_87013611 ( Report writer) Modification

    Hi , My requirement is to modify the standard report S_ALR_87013611 which developed on Report writer. It is drildown report writer report. It is calling the KSB1 transaction with user interaction. I want to modify the report by replacing the custom t

  • I've downloaded acrobat XI Pro, installed it, but get "Acrobat failed to connect to a DDE server error message.

    I've downloaded acrobat XI Pro, installed it, but get "Acrobat failed to connect to a DDE server error message.