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

Similar Messages

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

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

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

  • 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

  • Simple one to many mapping question

    Hi,
    In the Toplink tutorial there is a one to many relation between Employee and PhoneNumber, and one to one between PhoneNumber and Employee.
    If I don't require can I eliminate the one to one relationship between PhoneNumber and Employee. Or Toplink requires it?
    Thanks
    -Mani

    Hi,
    The purpose of creating one-to-one back reference mapping in the target is so that the foreign key information can be written when the target object is saved. Alternatives to the one-to-one mapping back reference include:
    Use a direct-to-field mapping to map the foreign key and maintain its value in the application. Here the object model does not require a back reference, but the data model still requires a foreign key in the target table.
    Use a many-to-many mapping to implement a logical one-to-many. This has the advantage of not requiring a back reference in the object model and not requiring a foreign key in the data model. In this model the many-to-many relation table stores the collection. It is possible to put a constraint on the join table to enforce that the relation is a logical one-to-many relationship.
    Raanan.

  • One-Sided One-to-Many Mapping

    Hi,
    the manual says: "You can, however, have one-sided one-to-many mappings in
    which the back-reference only exists in the database, and is not
    represented by any Java field. The mapping tool never creates a one-sided
    one-to-many relation like this; you can only create it by writing the
    mapping data yourself, and then only on an existing schema that supports
    it."
    I don't understand the meaning of the phrase "only on an existing schema
    that supports it". Does that mean it's not supported for all databases
    (which are supported)? And what does it mean "on an existing schema"?
    thanks
    Reto

    Whoops. Got it backwards.
    Should be
    q.declareParameters ("Article article");
    q.setFilter ("articles.contains (article)");
    Collection results = (Collection) q.execute (article);
    Stephen Kim wrote:
    If this is a one to many, Article can just return its owning magazine
    field.
    Otherwise you can issue a query usch as:
    Query q = pm.newQuery (Magazine.class);
    q.declareParameters ("magazine");
    q.setFilter ("articles.contains (magazine)");
    Collection results = (Collection) q.execute (magazine);
    bamboo wrote:
    Following is the example, the question is how can I get the magazine
    instance if I have an Article instance? Thanks.
    Java class:
    public class Magazine
    private Set articles;
    ... class content ...
    Schema:
    <table name="MAGAZINE">
    <column name="JDOID" type="bigint"/>
    <pk column="JDOID"/>
    ... columns for magazine fields ...
    </table>
    <table name="ARTICLE">
    ... primary key columns ...
    <column name="MAG_ID" type="bigint"/>
    <fk to-table="MAGAZINE">
    <join column="MAG_ID" to-column="JDOID"/>
    </fk>
    ... columns for article fields ...
    </table>
    JDO metadata:
    <class name="Magazine">
    <field name="articles">
    <collection element-type="Article"/>
    </field>
    ... rest of field metadata ...
    </class>
    Mapping information using the mapping XML format:
    <class name="Magazine">
    ... class mapping ...
    ... indicator mappings ...
    <field name="articles">
    <jdbc-field-map type="one-many" table="ARTICLE"
    ref-column.JDOID="MAG_ID"/>
    </field>
    ... rest of field mappings ...
    </class>
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • One to Many Mapping Expression

    I have two tables. Invoice & Accounts
    An Invoice can have many Accounts associated to it(one to many)
    i need to select all the invoices whose accounts belongs to a particular category and region
    Invoice has
    invoiceNo
    Accounts has
    AccountID
    AccountRegion
    AccountCategory
    InvoiceNo
    i made a expression like
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression exp1 = builder.anyOf("accCollection").get("accountRegion").equals("1");
    Expression exp2 = builder.anyOf("accCollection").get("accountCategory").equals("VIP");
    Expression exp3 = exp1.and(exp2);
    ReadAllQuery query = new ReadAllQuery(Invoice.class,exp3);
    query.setPartialAttribute("invoiceNo");
    query.dontMaintianCache();
    uow.executeQuery(query);
    The result is coming properly, but when i looked at the query, it is joining the Accounts table two times. when i increase the number of expression based on the Accounts table then it is joined as many times as there are in my query
    e.g.
    select t0.invoiceNo from Invoice to,Accounts t1,Accounts t2 ...
    How can i make the query so that the Accounts table will be used in the join only once??
    Sathish

    Do this, and all will be well:
    ExpressionBuilder builder = new ExpressionBuilder();
    Expression exp = builder.anyOf("accCollection");
    Expression exp1 = exp.get("accountRegion").equals("1");
    Expression exp2 = exp.get("accountCategory").equals("VIP");
    Expression exp3 = exp1.and(exp2);
    Think of it as building a tree and the SQL will build down the branches.
    - Don

  • Sorted one-to-many mapping

    Hi,
    I try to use a one-to-many relationship (join) with a sorted condition.
    I don't know how if I have to use transparent Indirection and how to customize my condition (ascending).
    regards

    That would be the name of the query key of the related class.
    Consider A (id, name, listOfBs) and B (id, name).
    To sort listOfBs based on the "name" attribute of B, I would use the argument "name" to the addAscending/addDescendingOrdering method.
    I hope this clarifies things for you,
    Christian

  • One-to-many mapping to existing schema

    I've been playing with the Kodo eval for a couple of days now, and have run
    into a brick wall. My problem is probably trivial, but I'm afraid I can't
    get it to work:
    I have the following existing tables that model a 1-m mapping between users
    and their details:
    - Table User with columns ID, Name, SSN.
    - Table UserDetails with column UserID (foreign key to User.ID) and some
    data columns (phone number and so on).
    Note that UserDetails has no primary key column.
    I would like to map these to two classes: User and UserDetail.
    - Class User has a Collection member named "details_". Each element in this
    collection is a UserDetail object.
    - Class UserDetail has no reference to User.
    In other words, UserDetail objects are SCOs, if I understand the JDO spec
    correctly.
    I cannot find the right metadata to support this mapping. The pet shop
    tutorial has an example (the "giTract") in which the objects on the "many"
    side have identity. The reverse tutorial has an example ("articleSubtitles")
    in which the "many" side is a simple string stored in a single column, not a
    user-defined class with several fields that have to map to several columns.
    So neither of these examples seem to carry through to my case.
    Any help would be greatly appreciated.
    Thanks and happy new year,
    ~Benjy

    Patrick,
    Thanks for the prompt response.
    I tried something similar to what you described, but using datastore
    identity. I set the pk-column on the UserDetails class to UserID using the
    extension tag.
    However when I iterate over the UserDetail objects belonging to a single
    User, I keep getting the first instance back for each call to next() on the
    iterator. This is presumably because all UserDetail objects have the same
    UserID, hence the same PK, so the PM returns the same instance, as it
    should. The PK for the user details needs to be truly unique, and there's no
    way I can guarantee that, even with application identity (I might have two
    instances of UserDetails that are identical in value).
    From reading past postings on this group I believe my problem can be
    rephrased as "can I implement one-way 1-m relationships". I saw a post
    suggesting that this would be available in a future release. Any idea when
    this might happen? It seems to already be implemented for types that can be
    put in a single column (as in the "articleSubtitles" case).
    Thanks,
    Benjy
    "Patrick Linskey" <[email protected]> wrote in message
    news:[email protected]...
    Benjy,
    As you've deduced, the UserDetails table must have some "primary key"
    data. This does not need to be an actual database primary key, however.
    So, based on your description, you should probably be able to get away
    with using the UserID column as the JDO primary key column. To do this,
    you'll have to use application identity (so that you can control the
    setting of this column) and create a field for the UserID column in your
    UserDetails class.
    Also, you must take care to ensure that all Java fields that use the
    UserID column for data storage are set to the same value. Provided that
    this is the case, Kodo will deal with the duplicate entries, but if Kodo
    detects that you're trying to set a column to multiple different values,
    Kodo will complain.
    -Patrick
    Benjy Weinberger wrote:
    I've been playing with the Kodo eval for a couple of days now, and
    have run
    into a brick wall. My problem is probably trivial, but I'm afraid I
    can't
    get it to work:
    I have the following existing tables that model a 1-m mapping between
    users
    and their details:
    - Table User with columns ID, Name, SSN.
    - Table UserDetails with column UserID (foreign key to User.ID) and some
    data columns (phone number and so on).
    Note that UserDetails has no primary key column.
    I would like to map these to two classes: User and UserDetail.
    - Class User has a Collection member named "details_". Each element in
    this
    collection is a UserDetail object.
    - Class UserDetail has no reference to User.
    In other words, UserDetail objects are SCOs, if I understand the JDOspec
    correctly.
    I cannot find the right metadata to support this mapping. The pet shop
    tutorial has an example (the "giTract") in which the objects on the"many"
    side have identity. The reverse tutorial has an example
    ("articleSubtitles")
    in which the "many" side is a simple string stored in a single column,
    not a
    user-defined class with several fields that have to map to several
    columns.
    So neither of these examples seem to carry through to my case.
    Any help would be greatly appreciated.
    Thanks and happy new year,
    ~Benjy
    Patrick Linskey [email protected]
    SolarMetric Inc. http://www.solarmetric.com

Maybe you are looking for