Variable one to one mapping question

I'm trying to create a variable one to one mapping using an interface with two implementing classes. The problem that I have is that I have two different values in the class indicator column that I wish to map to the same class. Mapping workbench doesn't let me do this. The MW documentation discusses using unique primary keys by leaving the class indicator blank. However, i'm using 9.0.4.8 and this doesn't appear to work as I get exceptions at runtime.
Is there anything along the lines of the inheritance classextraction method for interfaces? Any suggestions for how to go about this?
Thanks in advance,
Jonathan

Hi Jonathan,
This use case is not supported in the Workbench. You will have to define an After Load Method in the workbench and add the indicator->class mappings in code. I am not positive on how this is handled in the runtime. Which indicator would be used when writing, maybe only supported for read-only mappings, or possibly not supported at all? Someone from the runtime team can respond about this.
Karen

Similar Messages

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

  • One to one mapping question -- can I just map a lookup field for queries?

    I have a table with a state code. I'd like to have a "virtual lookup" on the java class to a region table. I.e., this java class "studies" has a state code. I can map a one-to-one to the descriptor class that has the ref table, but I'd like to have a property in the java class pre-mapped to the "region" field in this lookup so for querying i can just use:
    ReadAllQuery q = new ReadAllQuery();
    q.setReferenceClass(study.class);
    q.setSelectionCriteria(new ExpressionBuilder().get("Region").equal(Region));
    to get all the studies for a particular region.
    am I going about this wrong? or do I have to get the reference table descriptor fromt he one to one map and do something different?

    well,on the way home last nite, I realized I'd had a complete brain fart. I've done this before. I just set up a 1-1 map between descriptors and then built the query like this:
    q.setSelectionCriteria(new ExpressionBuilder().get("refFPO").get("FPO_NO").equal(FPO));
    You can get the pointer to the "refFPO" which is the the descriptor mapped 1-1, then appended the column you wish to get.
    I still went ahead and amended my class to include a read-only, non-toplink mapped attribute "FPO" which just gets the reference variable pointing to "refFPO.getFPO_NO();
    I answered my own question just in case anyone wondered ....

  • Variable One to One - difficult question

    Hi
    I am using a Variable One to One mapping but TL is not using the class indicator information to produce the correct SQL and I wonder what I am doing wrong.
    I have the following simplified database design:
    Users:
    userId (pk)
    Applications:
    applicationId (pk)
    ServiceProviders
    serviceProviderId (pk)
    applicationId (fk)
    Services
    serviceId (pk)
    serviceProviderId (fk)
    UserEntities
    userId (pk, fk)
    entityId (pk)
    entityTypeId (pk)
    The Id values for different entity types are mutually exclusive - there can be a serviceId #1 and a serviceProviderId #1.
    I have several classes that implement an Entity interface (Application, ServiceProvider, Service), and a UserEntity class containing a reference to a User and an Entity.
    In the descriptors for classes implementing Entity I have a one to many mapping to UserEntity, with a table reference constructed in MW, and a single source / target field pair of e.g. entityId - applicationId. In the UserEntity descriptor I have a one to one mapping to User and a variable one to one mapping to Entity. This contains a Class Indicator based on the entityTypeId field, and values for each class implementing Entity have been entered.
    It seems that when I insert a new UserEntity instance, this class indicator value is used to supply a value for the entityTypeId field. When I access the userEntities collection from a User instance, the class indicator is used to instantiate the correct kind of Entity. But when I access the userEntities collection from an instance of the an Entity class like the Application class, the EntityTypeId is not specified in the SQL generated:
    ServerSession(30932017)--Connection(24156236)--SELECT ENTITYID, ENTITYTYPEID, USERID FROM USERENTITIES WHERE (ENTITYID = ?)
    bind => [1]
    #### I would expect 'AND ENTITYTYPEID = ? ..... bind => [2]' here #####
    I would expect the class indicator info to be used both ways, when determining what class to instantiate for the variable one to one, and also to make the query specific to that class when an instance is being used.
    Many thanks if you can shed some light on this. Perhaps I have to use an API method as demonstrated in this post how can i map this?
    James

    James
    Thanks for your reply.
    I have a similar NullPointerException on the validateNode method. I slavishly followed your code example - hope it was right :), so will raise this with Oracle support.
    public static void amendApplicationUserEntityResp(Descriptor descriptor) {
         OneToManyMapping mapping = (OneToManyMapping) descriptor.getMappingForAttributeName("responsibilitiesInherited");
         ExpressionBuilder builder = new ExpressionBuilder();
         mapping.setSelectionCriteria(
              builder.getField("USERENTITYRESPINHERITED.ENTITYID").equal(builder.getParameter("APPLICATIONS.APPLICATIONID")
              .and(builder.getField("USERENTITYRESPINHERITED.ENTITYTYPEID").equal(1)))

  • Variable One-to-one mapping

    i am working on variable one-to-one mapping. i am unable to figure out how to work on it. can anybody provide an example on how to implement it from java and toplink perspectives.

    Thank you. I have gone through the links. i used class indicator field method. I am still getting error saying
    "Exception Description: Missing descriptor for [class java.lang.String]. Verify that the descriptor has been properly registered with the Session."
    My code and table structure is as below.
    Interface - VariableOneToOne
    Implementation classes: Phone and Email
    Table Structure:
    Employee Table:
    ID (PK)
    Name
    TYPE (mapped as variable one-to-one)
    C_ID(FK to eid and pid)
    Phone Table:
    pid (PK)
    phnumber
    Email Table:
    eid (PK)
    emailaddress
    "TYPE" is of string type. "Phone" or "Email" is sent from this attribute. Toplink instantiates the respective class from the configurations specified in the variable one-to-one mapping of "TYPE" attribute in workbench.
    The classes and interface code is as below:
    Inteface:
    package com.cts;
    public interface VariableOneToOne {
         public int getId();
         public void setId(int id);
    Employee Class:
    package com.cts;
    public class Employee2{
         protected int id;
         protected String name;
         protected String type;
         protected VariableOneToOne phone;
         protected VariableOneToOne email;
         public Employee2()
              this.id = 0;
              this.name = null;
              this.type = null;
              this.phone = null;
              this.email = null;
         public int getId() {
              return id;
         public void setId(int id) {
              this.id = id;
         public String getName() {
              return name;
         public void setName(String name) {
              this.name = name;
         public String getType() {
              return type;
         public VariableOneToOne getEmail() {
              return email;
         public void setEmail(VariableOneToOne email) {
              this.email = email;
         public VariableOneToOne getPhone() {
              return phone;
         public void setPhone(VariableOneToOne phone) {
              this.phone = phone;
         public void setType(String type) {
              this.type = type;
    Email Class:
    package com.cts;
    public class Email2 implements VariableOneToOne {
         protected int id;
         protected String email;
         public Email2() {
              this.id = 0;
              this.email = null;
         public String getEmail() {
              return email;
         public void setEmail(String email) {
              this.email = email;
         public int getId() {
              return id;
         public void setId(int id) {
              this.id = id;
    Phone Class:
    package com.cts;
    public class Phone2 implements VariableOneToOne {
         protected int id;
         protected String phone;
         public Phone2()
              this.id = 0;
              this.phone = null;
         public int getId() {
              return id;
         public void setId(int id) {
              this.id = id;
         public String getPhone() {
              return phone;
         public void setPhone(String phone) {
              this.phone = phone;
    Please advice on resolving the issue.
    Thanks in advance.

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

  • How to use bind variable value of one VO as initial value for other VO row?

    JDeveloper 10.1.3.3, ADF Faces, ADF BC
    Hi,
    I have two View Objects: one read only with several bound variables and another editable entity based. Correspondingly there are two ADF Faces pages: first contains search form based on the read-only VO and second create form based on the editable VO. The search form has several hidden fields for some of bound variables because they aren't edited directly by user. These fields are updated with PPR when user selects other search criteria from LOV.
    There is a command button in the first page that navigates to the second form. Is there any way to transfer values of bound variables from the first VO to the second VO as initial values of the new row?
    I tried to set custom controller for the second page and retrieve search criteria values from request parameter map but values from hidden fields are missing. I think because that these fields are updated by PPR. Of course I can add custom action method to the navigation button and in the method put these values to request parameter map but I hope there is better solution.
    Thanks,
    Marius

    To summarize, given a bind variable value for one VO, on creating a row in a second VO, for 1 of the attributes of the second VO, you want to use the first VO's bind variable value. Correct?
    A potential solution ADF BC driven:
    1) Ensure you have an AppModuleImpl for your AM
    2) Ensure you have a ViewImpl for your 1st VO (where the bind variable will exist) - lets refer to that VO as "Alpha"
    3) Ensure you have a ViewRowImpl for your 2nd VO (the one you want to default the value in) - lets refer to that VO as "Beta"
    4) For your first VO "Alpha" create the bind variable (say pValue)
    5) In your second VO "Beta" ViewRomImpl add following code:
    @Override
    protected void create(AttributeList attributeList) {
      super.create(attributeList);
      AppModuleImpl am = (AppModuleImpl)this.getApplicationModule();
      String someValue = am.getAlphaView1().getpValue();
      setSecondVOAttr(someValue); // change this code to whatever your setter is for the field you want to initialize.
    }Hope this helps. Let us know how you go.
    Regards,
    CM.

  • Wants to avoid mapping for an one-to-one scenario..details in the message

    Hello Experts,
    Need your help on the below problem.
    We are in
    Service Pack: 08
    Release: NW711_08_REL
    Scenario : proxy to file(tab separated)
    mapping: one to one
    structure:
    msgname
      -recordset (0..n)
          -field1 (0..1)
          -field2 (0..1)
          -field3 (0..1)
    FCC setting
    Recordset.fieldSeparator : '0x09'
    Recordset.endSeparator : 'nl'
    In the target file always all the tabs should appear irrespective of the field contain. There are chances that some field might not get populated in the proxy and hence that tag itself might not appear. Right now to achieve this we are using an one-to-one mapping with "mapwithdefault" for all the fields.
    Question: is it possible to achieve this without any mapping? If yes is there something we need to do in the FCC part or somewhere else?
    Quick answer appreciated.
    Thanks
    Sanjay

    you can avoid Mapping only if your sender and receiver both structures are same (along with name). even if there is Field name change you have to have mapping.
    but if your both (Sender and receiver structures) are same and identical then you can avoid mapping and even Operation mapping in PI 7.1
    Thanks,
    Bhupesh

  • Horizontal mapping + embedded one-to-one problem

    Hi,
    this message corresponds to the article "Embedded One-to-One mapping
    problem". But this article is more exactly then the first without less
    unnessary information.
    I got an abstract super-class Person which is mapped horizontal.
    Student inherits from Person.
    Person contains an attribute called location(instance of Class Location)
    which should be mapped "embedded one-to-one".
    Since Person is mapped horizontal no table will be used for Person.
    I get following exception when running mappingtool on action "buildSchema"
    kodo.jdbc.meta.MappingInfoNotFoundException: No mapping information was
    found for "xxx.yyy.zzz.persistence.jdo.business.Location.lat"
    I think Kodo tries to map the field "location" since the field is declared
    as embedded. But it can not embed the field since Person is horizontal
    mapped and no table for Person exists where the corresponding field of
    Location could be placed in. Also it is not possible to set the "embedded"
    attribute in the subclass Student for the field "location" because it must
    be specified in the superclass.
    Can you help me ?
    Thanks a lot,
    Felix
    Additional information:
    =======================
    Exception stack trace:
    [mappingtool] kodo.jdbc.meta.MappingInfoNotFoundException: No mapping
    information was found for "xxx.yyy.zzz.persistence.jdo.business.Location".
    [mappingtool] at
    kodo.jdbc.meta.RuntimeMappingProvider.getMapping(RuntimeMappingProvider.java:44)
    [mappingtool] at
    kodo.jdbc.meta.MappingRepository.getMappingInternal(MappingRepository.java:352)
    [mappingtool] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:307)
    [mappingtool] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:162)
    [mappingtool] at
    kodo.jdbc.meta.MappingTool.buildSchema(MappingTool.java:646)
    [mappingtool] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:951)
    [mappingtool] at
    kodo.jdbc.ant.MappingToolTask.executeOn(MappingToolTask.java:175)
    [mappingtool] at com.solarmetric.ant.TaskBase.execute(TaskBase.java:105)
    [mappingtool] at
    org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
    [mappingtool] at org.apache.tools.ant.Task.perform(Task.java:364)
    [mappingtool] at org.apache.tools.ant.Target.execute(Target.java:301)
    [mappingtool] at
    org.apache.tools.ant.Target.performTasks(Target.java:328)
    [mappingtool] at
    org.apache.tools.ant.Project.executeTarget(Project.java:1215)
    [mappingtool] at
    org.apache.tools.ant.Project.executeTargets(Project.java:1063)
    [mappingtool] at org.apache.tools.ant.Main.runBuild(Main.java:632)
    [mappingtool] at org.apache.tools.ant.Main.startAnt(Main.java:183)
    [mappingtool] at
    org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
    [mappingtool] at
    org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
    Here is the JDO-Metadata:
    <?xml version="1.0" encoding="UTF-8"?>
    <jdo>
    <package name="xxx.yyy.zzz.persistence.jdo.business">
    <class name="Location"/>
    <class name="Person" identity-type="application"
    objectid-class="PersonId">
    <field name="location" embedded="true"/>
    <field name="id" primary-key="true"/>
    </class>
    <class name="Student" identity-type="application"
    persistence-capable-superclass="Person"/>
    </package>
    </jdo>
    Here is the mapping-metadata:
    <?xml version="1.0" encoding="UTF-8"?>
    <mapping>
    <package name="xxx.yyy.zzz.persistence.jdo.business">
    <class name="Person">
    <jdbc-class-map type="horizontal"/>
    </class>
    <class name="Student">
    <jdbc-class-map type="base" table="STUDENT"/>
    <jdbc-version-ind type="version-number" column="JDOVERSION"/>
    <jdbc-class-ind type="in-class-name" column="JDOCLASS"/>
    <field name="Person.birthDate">
    <jdbc-field-map type="value" column="BIRTHDATE"/>
    </field>
    <field name="Person.city">
    <jdbc-field-map type="value" column="CITY"/>
    </field>
    <field name="Person.id">
    <jdbc-field-map type="value" column="ID"/>
    </field>
    <field name="Person.location">
    <jdbc-field-map type="embedded"
    null-ind-column="NULL_INDICATOR" synthetic="false">
    <field name="lat">
    <jdbc-field-map type="value" column="LATITUDE"/>
    </field>
    <field name="lon">
    <jdbc-field-map type="value" column="LONGITUDE"/>
    </field>
    </jdbc-field-map>
    </field>
    <field name="Person.name">
    <jdbc-field-map type="value" column="NAME"/>
    </field>
    <field name="Person.picture">
    <jdbc-field-map type="value" column="PICTURE"/>
    </field>
    <field name="Person.state">
    <jdbc-field-map type="value" column="STATE"/>
    </field>
    <field name="Person.street">
    <jdbc-field-map type="value" column="STREET"/>
    </field>
    <field name="Person.zipcode">
    <jdbc-field-map type="value" column="ZIPCODE"/>
    </field>
    </class>
    <class name="Location">
    <jdbc-class-map type="none"/>
    <field name="lat">
    <jdbc-field-map type="none"/>
    </field>
    <jdbc-class-map type="none"/>
    <field name="lon">
    <jdbc-field-map type="none"/>
    </field>
    </class>
    </package>
    </mapping>
    Here are the class definitions:
    Class Location:
    public class Location {
         private int lat;
         private int lon;
    Class Person:
    public abstract class Person {
    private int id;
    private String name;
    private String street;
    private String city;
    private String state;
    private String zipcode;
    private Date birthDate;
    private String picture;
    private Location location;
    Class Person:
    public class Student extends Person {

    You'll probably have much better luck sending this question to
    [email protected]; the newsgroup is generally for quick questions
    about certain features or problems the community might be able to solve
    without input from SolarMetric developers.

  • How to query objects on variable one-to-one relationship

    Hi,
    I have a situation here:
    Application (APPLICATION table) has many payoffs (Payoff table); Primary key of application is the foreign key of payoff.
    Payoff has disbursement, such as check(check table), directDeposit(directDeposit table) or Wire(wire table), which is variable one-to-one relationship. They share the same primary key
    The query I need to run is to search application based on check number, How do I construct a query to perform this kind of search?
    Thanks
    Hao
    [email protected]

    Hi Doug,
    Thanks for all your help. But I guess I still need more details from you to help me understand the solution.
    First of all, I want to make sure I make my case clear
    Application (application table, pk: uniqueAppId) has many payoffs (Payoff table, pk: payoffId);
    Payoff object has variable one-to-one mapping to Disbursement object, which is a abstract super clss for following objects:
    Check(payoff-check table, pk: payoffId)
    DirectDeposit(payoff-deposit table, pk: payoffId)
    Wire(payoff-wire table, pk: payoffId),
    The query I want to run is to get me back an application for a particular check number
    From you email, first I thought "check" is a object, then your sample code showed it is a string. So I am kind of confused. The document you pointed seems not reflect my case. I wonder it is because I didn't present my case clear the first time.
    Looking forward to your further help
    Hao

  • Aggregate and variable one-to-one

    Hi,
    I would like to create a variable one-to-one mapping in my aggregate target descriptor, but when I want to set up the query key associations, the foreign key field is disabled. Is this not possible, or am I missing something?
    Regards,
    Katarina

    Hi,
    I would like to create a variable one-to-one mapping in my aggregate target descriptor, but when I want to set up the query key associations, the foreign key field is disabled. Is this not possible, or am I missing something?
    Regards,
    Katarina

  • Variable one to one

    Hi,
    1) Is it possible to have the class indicator in a variable one to one mapping set to a function call, or a pl/sql expression instead of a field?
    2) I am trying to use the workbench to create a variable one to one but the reference descriptor dropdown does not show anything.
    Thanks!
    Calin

    1 - You could use custom SQL or stored procedures in your queries to read the source object of the variable 1-1 and potentially provide the indicator value from a function, but this would be very complex. You would probably be better off having an indicator field, or not using an indicator (it is optional). Perhaps some more information on what you are trying to do?
    2 - A variable 1-1 mapping is a 1-1 relationship from the source descriptor to one of several different classes that share a common interface. You must have a common interface between the target classes and define an interface descriptor for the interface in the Mapping Workbench.

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

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

Maybe you are looking for