Toplink mapping for one-to-many object inheritance

Hi
I currently have a Person object, extended by two specialist classes, PremisesLicenceHolder and PersonalLicenceHolder. I have mapped this in Toplink and it works fine saving a person into the specialist tables using the primary key person_id.
However, a single Person may be extended any number of times by either one or both of the two specialist types. So, a Person may be a PremisesLicenceHolder many times over for different premises and licences, and also a PersonalLicenceHolder several times over.
Is it possible to map this object model in Toplink avoiding duplicate person_id primary keys in the specialist tables?
Thanks

Hi,
I am happy that my object model fits the problem domain. The Person and Organisation objects contain base information and have the primary keys person_id and organisation_id. It is important that there is no duplication of person and organisation records, no matter how many times they are saved in different roles.
There are two types of licenceholder in the problem domain, and the ILicenceHolder interface defines information and methods that are common to both. The PersonalLicenceHolder object represents one of these types of licenceholder, and is always a person, so this class extends Person and implements ILicenceHolder.
The additional information and methods that are required by the second type of licenceholder are defined in the interface IPremisesLicenceHolder, which extends ILicenceHolder. Premises licence holders can either be people or organisations, so I have two objects to represent these - PremisesLicenceHolderPerson which implements IPremisesLicenceHolder and extends Person, and PremisesLicenceHolderOrganisation which implements IPremisesLicenceHolder and extends Organisation.
The model is further complicated by the fact that any single Person may be both a PersonalLicenceHolder and a PremisesLicenceHolderPerson, and may be so several times over. In this case, the same basic Person information needs to be linked to several different sets of licenceholder information. In the same way, any single Organisation may be a PremisesLicenceHolderOrganisation several times over.
Sorry this is complicated!
My initial idea for the schemas is to have Person and Organisation tables containing the basic information with the primary keys person_id and organisation_id. The Person table would have a one-to-many relationship with both the PersonalLicenceHolder table (pk: personalLicenceHolder_id, fk: person_id), and the PremisesLicenceHolderPerson table (pk: premisesLicenceHolderPerson_id, fk: person_id). There would also be a one-to-many relationship between the Organisation table and the PremisesLicenceHolderOrganisation table (pk: premisesLicenceHolderOrganisation_id, fk: organisation_id).
I am flexible as to the design of my schema though, as I am happy to adopt any that will facilitate the Toplink Mapping.
Thanks for your help with this.

Similar Messages

  • Help with multi-table mapping for one-to-many object inheritance

    Hi,
    I have posted on here before regarding this (Toplink mapping for one-to-many object inheritance but I am still having problems mapping my object model to my schema.
    Object model
    The Person and Organisation objects contain base information and have the primary keys person_id and organisation_id. It is important that there is no duplication of person and organisation records, no matter how many times they are saved in different roles.
    There are two types of licenceholder in the problem domain, and the ILicenceHolder interface defines information and methods that are common to both. The PersonalLicenceHolder object represents one of these types of licenceholder, and is always a person, so this class extends Person and implements ILicenceHolder.
    The additional information and methods that are required by the second type of licenceholder are defined in the interface IPremisesLicenceHolder, which extends ILicenceHolder. Premises licence holders can either be people or organisations, so I have two objects to represent these - PremisesLicenceHolderPerson which implements IPremisesLicenceHolder and extends Person, and PremisesLicenceHolderOrganisation which implements IPremisesLicenceHolder and extends Organisation.
    The model is further complicated by the fact that any single Person may be both a PersonalLicenceHolder and a PremisesLicenceHolderPerson, and may be so several times over. In this case, the same basic Person information needs to be linked to several different sets of licenceholder information. In the same way, any single Organisation may be a PremisesLicenceHolderOrganisation several times over.
    Sorry this is complicated!
    Schema
    I have Person and Organisation tables containing the basic information with the primary keys person_id and organisation_id.
    I have tried to follow Donald Smith's advice and have created a Role table to record the specialised information for the different types of licence holder. I want the foreign keys in this table to be licenceholder_id and licence_id. Licenceholder_id will reference either organisation_id or person_id, and licence_id will reference the primary key of the Licence table to link the licenceholder to the licence. Because I am struggling with the mapping, I have changed licenceholder_id to person_id in an attempt to get it working with the Person object before I try the Organisation.
    Then, when a new licenceholder is added, if the person/organisation is already in the database, a new record is created in the Role table linking the existing person/organisation to the existing licence rather than duplicating the person/organisation information.
    Mapping
    I am trying to use the toplink mapping workbench to map my PremisesLicenceHolderPerson object to my schema. I have mapped all inherited attributes to superclass (Person). The primary table that the attributes are mapped to is Person, and I have used the multi-table info tab to add Roles as an additional table and map the remaining attributes to that.
    I have created the references PERSON_ROLES which maps person.person_id to roles.person_id, ROLES_PERSON which maps roles.person_id to person.person_id and ROLES_LICENCE which maps roles.licence_id to licence.licence_id.
    I think I have put in all the relationships, but I cannot get rid of the error message "The following primary key fields are unmapped: PERSON_ID".
    Please can somebody tell me how to map this properly?
    Thank you.

    I'm not positive about your mappings, but it looks like the Person object should really have a 1:M or M:M mapping to the Licenceholder table. This then means that your object model should be similar, in that Person object could have many Licenses, instead of being LicenceHolders. From the looks of it, you have it set up from the LicenceHolder perspective. What could be done instead if a LicenceHolder could have a 1:1 reference to a person data object, rather than actually be a Person. This would allow the person data to be easily shared among licences.
    LicenceHolder1 has an entry in the LicenceHolder table and Person table. LicenceHolder2 also has entries in these tables, but uses the same entry in the Person table- essentially it is the same person/person_ID. If both are new objects, TopLink would try to insert the same person object into the Person table twice. I'm not sure how you have gotten around or are planning to get around this problem.
    Since you are using inheritance, it means that LicenceHolder needs a writable mapping to the person.person_id field- most commonly done through a direct to field mapping. From the description, it looks like roles.person_id is a foreign key in the multiple table mapping, meaning it would be set based on the value in the person.person_id field, but the person.person_id isn't actually mapped in the object. Check to make sure that the ID attribute LicenceHolder is inheriting from person hasn't been remapped in the LicenceHolder descriptor to a different field.
    Best Regards,
    Chris

  • What types of containers need to be used for one-to-many relationships

    While looking at toplink examples, I noticed that synchronized containers only are being used for one-to-many relationships even though it's not required by the documentation.
    Is it required?
    Also how does merge affect it? I'm gettning concurrent modification exceptions from time to time, while using iterators for containers from these relationships.
    Does it mean that I have to use enumeration on vectors only and toplink merge isn't atomic? So there is no isolation when toplink merges the data from unit of work into identity maps?
    There is nothing about thread-safety and threading aspects of accessing containers for CollectionMapping based relationships. Please advise.

    Non synchronized containers can be used but may require some extra code to handle concurrent access. If you are accessing the objects from the shared cache (not cloned in a UnitOfWork) then you will need to isolate your iteration within a synchronized block, synchronized on the collection itself, or handle the ConncurrentModificationException if they happen rarely.
    Because these are shared instances of these collections other threads may be writing to them while they are being read from.
    --Gordon

  • Java.io.NotSerializableException - while retriving "one to many" objects

    i am getting java.rmi.MarshalException java.io.NotSerializableException
    while i try to retrive one to many objects
    i have recently migrated from kodo 2.5.x to kodo 3.0.1, and i have parent
    object reference in child objects (reverse mapping reference according to
    kodo 2.5.x) as shown below
    public class BankStatementEntry implements BankStatement {
    private Set accountSummary = new HashSet();
    public interface BankStatement extends Serializable {
    * Returns the accountSummary.
    * @return Map
    public Set getAccountSummary();
    * Returns the accountSummary.
    * @return Map
    public void setAccountSummary(Set accountSummary);
    public class AccountSummaryRecord implements AccountSummary {
    private BankStatementEntry bankStatementEntry;
    public interface AccountSummary extends Serializable {
         * Returns the transactionDetails.
         * @return Collection
         public Set getTransactionDetails();
    the problem is, when i try to retrive BankStatementEntry object, i have to
    iterate through each child (AccountSummaryRecord) object and manualy
    remove parent object reference (BankStatementEntry) by setting null.
    Otherwise EJB throws java.io.NotSerializableException
    Is this bug ?
    Thanks
    karup.

    Thread [Servlet.Engine.Transports : 1] (Suspended)
         java.io.NotSerializableException.<init>() line: 50 [local variables
    unavailable]
         com.ibm.CORBA.iiop.UtilDelegateImpl.copyObjectByProxy(java.lang.Object,
    org.omg.CORBA.ORB, java.lang.ClassLoader, java.lang.Class,
    org.omg.CORBA.portable.Streamable) line: 1316 [local variables unavailable]
         com.ibm.ws.orb.WSUtilDelegateImpl(com.ibm.CORBA.iiop.UtilDelegateImpl).copyObject(java.lang.Object,
    org.omg.CORBA.ORB) line: 771 [local variables unavailable]
         javax.rmi.CORBA.Util.copyObject(java.lang.Object, org.omg.CORBA.ORB)
    line: 327 [local variables unavailable]
         au.com.aig.aiaa.paymentdishonor.process.ejb._BankStatementProcessor_Stub.fetchBankStatement(java.util.Date,
    java.util.Date) line: 366
         au.com.aig.aiaa.business.process.ejb.CommonFacadeBean.fetchBankStatement(java.util.Date,
    java.util.Date) line: 102
         au.com.aig.aiaa.business.process.ejb.EJSRemoteStatelessCommonFacade_aa40cc36.fetchBankStatement(java.util.Date,
    java.util.Date) line: 61
         au.com.aig.aiaa.business.process.ejb._CommonFacade_Stub.fetchBankStatement(java.util.Date,
    java.util.Date) line: 266
         au.com.aig.aiaa.paymentdishonor.web.ReportsAction.execute(org.apache.struts.action.ActionMapping,
    org.apache.struts.action.ActionForm,
    javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse) line: 67
         org.apache.struts.action.RequestProcessor.processActionPerform(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse, org.apache.struts.action.Action,
    org.apache.struts.action.ActionForm,
    org.apache.struts.action.ActionMapping) line: 446
         org.apache.struts.action.RequestProcessor.process(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse) line: 266
         org.apache.struts.action.ActionServlet.process(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse) line: 1292
         org.apache.struts.action.ActionServlet.doGet(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse) line: 492
         org.apache.struts.action.ActionServlet(javax.servlet.http.HttpServlet).service(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse) line: 740
         org.apache.struts.action.ActionServlet(javax.servlet.http.HttpServlet).service(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse) line: 853
         com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse) line: 110 [local variables unavailable]
         com.ibm.ws.webcontainer.servlet.StrictServletInstance(com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet)._service(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse) line: 174 [local variables unavailable]
         com.ibm.ws.webcontainer.servlet.IdleServletState.service(com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet,
    javax.servlet.ServletRequest, javax.servlet.ServletResponse) line: 313
    [local variables unavailable]
         com.ibm.ws.webcontainer.servlet.StrictServletInstance(com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet).service(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse) line: 116 [local variables unavailable]
         com.ibm.ws.webcontainer.servlet.ServletInstance.service(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse,
    com.ibm.ws.webcontainer.webapp.WebAppServletInvocationEvent) line: 258
    [local variables unavailable]
         com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(com.ibm.ws.webcontainer.servlet.ServletInstanceReference,
    javax.servlet.ServletRequest, javax.servlet.ServletResponse,
    com.ibm.ws.webcontainer.webapp.WebAppServletInvocationEvent) line: 42
    [local variables unavailable]
         com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse,
    com.ibm.ws.webcontainer.webapp.WebAppServletInvocationEvent) line: 40
    [local variables unavailable]
         com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(com.ibm.ws.webcontainer.webapp.WebAppRequest,
    javax.servlet.http.HttpServletResponse) line: 872 [local variables
    unavailable]
         com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse, boolean) line: 491 [local variables
    unavailable]
         com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(javax.servlet.ServletRequest,
    javax.servlet.ServletResponse) line: 173 [local variables unavailable]
         com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(javax.servlet.http.HttpServletRequest,
    javax.servlet.http.HttpServletResponse) line: 79 [local variables
    unavailable]
         com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(java.lang.Object)
    line: 199 [local variables unavailable]
         com.ibm.ws.webcontainer.srt.WebAppInvoker(com.ibm.ws.webcontainer.cache.invocation.CachedInvocation).handleInvocation(java.lang.Object)
    line: 71 [local variables unavailable]
         com.ibm.ws.webcontainer.cache.invocation.CacheableInvocationContext.invoke(java.lang.Object)
    line: 114 [local variables unavailable]
         com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(java.lang.String,
    com.ibm.ws.webcontainer.srp.ISRPConnection) line: 187 [local variables
    unavailable]
         com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(com.ibm.ws.webcontainer.oselistener.api.IOSEConnection)
    line: 331 [local variables unavailable]
         com.ibm.ws.webcontainer.http.HttpConnection.handleRequest() line: 56
    [local variables unavailable]
         com.ibm.ws.webcontainer.http.HttpConnection(com.ibm.ws.http.HttpConnection).readAndHandleRequest()
    line: 432 [local variables unavailable]
         com.ibm.ws.webcontainer.http.HttpConnection(com.ibm.ws.http.HttpConnection).run()
    line: 343 [local variables unavailable]
         com.ibm.ws.util.ThreadPool$Worker.run() line: 592 [local variables
    unavailable]

  • On activating persistent class: There is no mapping for one or more fields

    Hi all,
    I'm using an ECC 6.0 system.
    I've just created a persistent class and defined the persistence. When I try to activate the class activating fails and I get the message "There is no mapping for one or more fields."
    I did not, in fact, use all the fields of the database table I defined the persistence on. When I do use all the fields activating the class works without a problem.
    However, as far as I know it should be possible to select only some of the fields when defining the persistence (the only fields I have to select are all the key fields of the table and I've done this).
    Has anybody encountered the same problem or has anybody any idea on this?
    Cheers,
    Kathy

    Hi Kathy,
    this is exactly what I meant.
    If you'd like, then you can also take a look at the documentation: http://help.sap.com/saphelp_nw04/helpdata/en/b0/9d0a3ad259cd58e10000000a11402f/frameset.htm
    There under Mapping, you can find:
    "You must map all columns of a database table to attributes. If you only want to manage some of the columns using Object Services, you must create a database view."
    Making attributes private doesn't change the fact, that you still map all fields. If you have a lot of fields, which you don't want to map, then I will again suggest, that you define a DB-view. This will boost the performance of your implementation.
    In case you need "quality 1st" performance, then I would suggest to use an ABAP implementation with internal tables, instead of the Persistent Service.
    HTH,
    Hristo

  • How can I export a list of events for one of many calendars - e.g. "sailing" to use in Excel

    How can I export a list of events for one of many calendars - e.g. "sailing" to use in Excel?

    See this thread here
    Display number of emails by sender

  • Weblogic-cmp-rdbms-jar.xml for One-To-Many unidirectional relationship

    hi,
    I am trying to create a simple cmp One-To-Many unidirectional relationship and deploy the same in weblogic. Can someone help me with the weblogic-cmp-rdbms-jar.xml. Am attaching the weblogic-cmp-rdbms-jar. xml tht i am using as also the corresponding ejb-jar.xml. Pls. note tht i want a unidirectional relationship here. one i am tryng However i get this error:
    Error while reading 'META-INF/weblogic-cmp-rdbms-jar.xml'. The error was: Role 'Supplier supplies Products' of relationship 'Product Supplier' contains an invalid key-column value of 'productID'. The key-column must specify a primary key column in the related bean. However, there is no primary key column named 'productID' defined in the related bean 'ProductEJB' or else 'productID' is not being recognized due to case mismatch. My weblogic-cmp-rdbms-jar
    <?xml version="1.0"?>
    <!DOCTYPE weblogic-rdbms-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB RDBMS Persistence//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms-jar.dtd'>
    <weblogic-rdbms-jar>
    <weblogic-rdbms-bean>
         <ejb-name>SupplierEJB</ejb-name>
         <data-source-name>RJDataSource</data-source-name>
         <table-map>
               <table-name>AA_Supplier</table-name>
               <field-map>
                     <cmp-field>supplierID</cmp-field>
                     <dbms-column>supplierID</dbms-column>
               </field-map>
               <field-map>
                    <cmp-field>name</cmp-field>
                    <dbms-column>name</dbms-column>
               </field-map>
         </table-map>
    </weblogic-rdbms-bean>
    <weblogic-rdbms-bean>
           <ejb-name>ProductEJB</ejb-name>
           <data-source-name>RJDataSource</data-source-name>
           <table-map>
                 <table-name>AA_Product</table-name>
                 <field-map>
                      <cmp-field>productID</cmp-field>
                      <dbms-column>productid</dbms-column>
                 </field-map>
                 <field-map>
                      <cmp-field>description</cmp-field>
                      <dbms-column>description</dbms-column>
                 </field-map>
                 <field-map>
                      <cmp-field>basePrice</cmp-field>
                      <dbms-column>baseprice</dbms-column>
                 </field-map>
                <field-map>
                      <cmp-field>name</cmp-field>
                      <dbms-column>name</dbms-column>
                 </field-map>
                 <field-map>
                     <cmp-field>supplierID</cmp-field>
                       <dbms-column>supplierID</dbms-column>
                 </field-map>
            </table-map>
    </weblogic-rdbms-bean>
    <weblogic-rdbms-relation>
         <relation-name>Product Supplier</relation-name>
         <weblogic-relationship-role>
              <relationship-role-name>Supplier supplies Products</relationship-role-name>
              <relationship-role-map>
                   <column-map>
                        <foreign-key-column>supplierID</foreign-key-column>
                        <key-column>productID</key-column>
                   </column-map>
              </relationship-role-map>
         </weblogic-relationship-role>
         <weblogic-relationship-role>
              <relationship-role-name>Product supplied by Supplier</relationship-role-name>
              <relationship-role-map>
              <column-map>
                   <foreign-key-column>products</foreign-key-column>
                   <key-column>supplierID</key-column>
              </column-map>
              </relationship-role-map>
         </weblogic-relationship-role>
    </weblogic-rdbms-relation>
    </weblogic-rdbms-jar> My ejb-jar.xml
    <?xml version="1.0"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
    <ejb-jar>
         <enterprise-beans>
         <entity>
              <ejb-name>SupplierEJB</ejb-name>
              <home>com.tpt.practice.entityBeans.cmp.product.relationship.SupplierHome</home>
              <remote>com.tpt.practice.entityBeans.cmp.product.relationship.Supplier</remote>
              <ejb-class>com.tpt.practice.entityBeans.cmp.product.relationship.SupplierEJB</ejb-class>
              <persistence-type>Container</persistence-type>
              <prim-key-class>java.lang.String</prim-key-class>
              <reentrant>False</reentrant>
              <cmp-version>2.x</cmp-version>
              <abstract-schema-name>AA_Supplier</abstract-schema-name>
              <cmp-field>
                   <field-name>supplierID</field-name>
              </cmp-field>
              <cmp-field>
                   <field-name>name</field-name>
              </cmp-field>
              <primkey-field>supplierID</primkey-field>
              <ejb-ref>
                        <ejb-ref-name>ProducEJB</ejb-ref-name>
                        <ejb-ref-type>Entity</ejb-ref-type>
                        <home>com.tpt.practice.entityBeans.cmp.product.ProductHome</home>
                        <remote>com.tpt.practice.entityBeans.cmp.product.Product</remote>
                        <ejb-link>ProductEJB#ProductEJB.jar</ejb-link>
              </ejb-ref>
              <query>
                   <query-method>
                        <method-name>findByName</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Supplier AS a WHERE a.name =
                        ?1]]>
                   </ejb-ql>
              </query>
              <query>
                   <query-method>
                        <method-name>findAllSuppliers</method-name>
                        <method-params>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Supplier AS a WHERE a.supplierID
                        IS NOT NULL]]>
                   </ejb-ql>
              </query>
         </entity>
         <entity>
              <ejb-name>ProductEJB</ejb-name>
              <home>com.tpt.practice.entityBeans.cmp.product.relationship.ProductHome</home>
              <remote>com.tpt.practice.entityBeans.cmp.product.relationship.Product</remote>
              <local-home>com.tpt.practice.entityBeans.cmp.product.relationship.ProductLocalHome</local-home>
              <local>com.tpt.practice.entityBeans.cmp.product.relationship.ProductLocal</local>
              <ejb-class>com.tpt.practice.entityBeans.cmp.product.relationship.ProductEJB</ejb-class>
              <persistence-type>Container</persistence-type>
              <prim-key-class>com.tpt.practice.entityBeans.cmp.product.relationship.ProductPK</prim-key-class>
              <reentrant>False</reentrant>
              <cmp-version>2.x</cmp-version>
              <abstract-schema-name>AA_Product</abstract-schema-name>
              <cmp-field>
                   <field-name>productID</field-name>
              </cmp-field>
              <cmp-field>
                   <field-name>name</field-name>
              </cmp-field>
              <cmp-field>
                   <field-name>description</field-name>
              </cmp-field>
              <cmp-field>
                   <field-name>basePrice</field-name>
              </cmp-field>
              <cmp-field>
                   <field-name>supplierID</field-name>
              </cmp-field>
              <primkey-field>productID</primkey-field>
              <query>
                   <query-method>
                        <method-name>findByName</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.name =
                        ?1]]>
                   </ejb-ql>
              </query>
              <query>
                   <query-method>
                        <method-name>findByDescription</method-name>
                        <method-params>
                             <method-param>java.lang.String</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.description
                        = ?1]]>
                   </ejb-ql>
              </query>
              <query>
                   <query-method>
                        <method-name>findByBasePrice</method-name>
                        <method-params>
                             <method-param>double</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.basePrice =
                        ?1]]>
                   </ejb-ql>
              </query>
              <query>
                   <query-method>
                        <method-name>findExpensiveProducts</method-name>
                        <method-params>
                             <method-param>double</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.basePrice >
                        ?1]]>
                   </ejb-ql>
              </query>
              <query>
                   <query-method>
                        <method-name>findCheapProducts</method-name>
                        <method-params>
                             <method-param>double</method-param>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.basePrice <
                        ?1]]>
                   </ejb-ql>
              </query>
              <query>
                   <query-method>
                        <method-name>findAllProducts</method-name>
                        <method-params>
                        </method-params>
                   </query-method>
                   <ejb-ql>
                        <![CDATA[SELECT OBJECT(a) FROM AA_Product AS a WHERE a.productID
                        IS NOT NULL]]>
                   </ejb-ql>
              </query>
         </entity>
         </enterprise-beans>
         <relationships>
         <ejb-relation>
              <ejb-relation-name>Product Supplier</ejb-relation-name>
              <ejb-relationship-role>
                   <ejb-relationship-role-name>Supplier supplies Products</ejb-relationship-role-name>
                   <multiplicity>One</multiplicity>
                   <relationship-role-source>
                        <ejb-name>SupplierEJB</ejb-name>
                   </relationship-role-source>
                   <cmr-field>
                        <cmr-field-name>products</cmr-field-name>
                        <cmr-field-type>java.util.Collection</cmr-field-type>
                   </cmr-field>
              </ejb-relationship-role>
              <ejb-relationship-role>
                   <ejb-relationship-role-name>Product supplied by Supplier</ejb-relationship-role-name>
                   <multiplicity>Many</multiplicity>
                   <relationship-role-source>
                        <ejb-name>ProductEJB</ejb-name>
                   </relationship-role-source>
              </ejb-relationship-role>
         </ejb-relation>
         </relationships>
         <assembly-descriptor>
              <container-transaction>
              <method>
                   <ejb-name>SupplierEJB</ejb-name>
                   <method-intf>Remote</method-intf>
                   <method-name>*</method-name>
              </method>
              <trans-attribute>Required</trans-attribute>
              </container-transaction>
         </assembly-descriptor>
    </ejb-jar>

    I think u r some confusion with productID and SuppliedID . primary key of one column( productId ) can be a foreign key of other table colum( SuppliedID). but foreign key( SuppliedID) can not be a primary key of second table .u declared SuppliedId as primary key . so ur mapping is incorrect.

  • How to get file names for one oracle directory object.

    Hi all ,
    I defined one oracle directory object . Now I want to know how many files stored under this object in physical directory and their names ? anyone know how to do it by pl/sql ?
    Thanks,
    George

    Chris Poole has an [XUTIL_FINDFILES package|http://www.chrispoole.co.uk/apps/xutlff.htm] which can do this in pure SQL. It does require, though, that your DBA install code in the SYS schema and that you rely on the behavior of an undocumented X$ table. That may not be possible in certain environments.
    I personally prefer a small Java stored procedure along the lines of [this one from Tom Kyte|http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:439619916584]. It isn't a pure PL/SQL solution, but it tends to fit relatively cleanly in any environment. Most DBAs will be willing to grant the privileges this sort of approach requires where they would be hesitant to grant the access necessary for XUTIL_FINDFILES.
    Justin

  • TopLink essentials: extra where clause for one to many relationship?

    We have a lot of tables that contain "historic" records. Those are marked by a column "historic" holding a value "Y". Sometimes we are not interested in historic values. For example in the next case:
    @Entity
    @Table(name="ART")
    public class Article {
        @OneToMany(mappedBy="article", cascade=CascadeType.ALL, fetch=FetchType.LAZY)
        private Collection<ArticleStats> arcItems;
        public Collection<ArticleStats> getArticleStats() {
            return arcItems;
    }One article can have multiple "stats". We are in this case only interested in the "stats" of this article that are not historic. In SQL terms, I would like to add an extra where clause: "WHERE historic = 'N'".
    Of course inheritance (with discriminators) is an option, but I don't prefer that. We have a lot of relationships like this and using inheritance would mean we have to add a lot of extra classes. Is there a way to add an extra where clause to the query that is used to retrieve all the stats records related tot my Article?
    We use TopLink essentials with an IBM AS/400 database.

    The JPA Spec does not handle this case, but TopLink Essentials does. You will need to customize your TopLink descriptor using a DescriptorCustomizer. You can set your DescriptorCustomizer in your persistence.xml using the "toplink.descriptor.customizer.<entity-name>" property set to the class name "<package>.<class>" of your customizer class.
    The customizer would look something like:
    public class MyCustomizer implements DescriptorCustomizer {
    public void customize(ClassDescriptor descriptor) {
    OneToManyMapping mapping = (OneToManyMapping )descriptor.getMappingForAttributeName("arcItems");
    ExpressionBuilder builder = new ExpressionBuilder();
    mapping.setSelectionCriteria(builder.getField("STAT.ART_ID").equal(builder.getParameter("ART.ID").and(builder.getField("HISTORY").equal("N")));
    If you never wanted historical records you could also add this expression to your descriptor's additionalJoinExpression.
    James Sutherland

  • CMP mapping of one to many unidirectional in wl7.0

    Hi,
    I like to do the following:
    1) Map one bean corresponding to table A to many beans corresponding to table
    B 2) table B has two columns as the primary keys.
    3) One of the primary key column in table B is a foreign key pointing to the primary
    key of table A.
    4) bean corresponding to table A has the cmr Collection field
    I am not able to map this scenario. I guess the mapping is possible as long as
    each table has its own unrelated primary keys. If anyone has tried this, please...please...help.
    Thanks.

    Wrong newsgroup, needs to go to one of the ejb newsgroups.
    mbg
    "Sai S Prasad" <[email protected]> wrote in message
    news:3ec28167$[email protected]..
    >
    Hi,
    I like to do the following:
    1) Map one bean corresponding to table A to many beans corresponding totable
    B 2) table B has two columns as the primary keys.
    3) One of the primary key column in table B is a foreign key pointing tothe primary
    key of table A.
    4) bean corresponding to table A has the cmr Collection field
    I am not able to map this scenario. I guess the mapping is possible aslong as
    each table has its own unrelated primary keys. If anyone has tried this,please...please...help.
    >
    >
    Thanks.

  • One to one mapping and one to many mapping in a single table

    Hi All,
    I am asked to design a banking application, I have CUSTOMER table where the information regarding the customer is stored. I have have an ACCOUNT table where account information is stored.
    Now A customer can start all the 3 types of accounts. (Checking account, Saving account and FD(Fixed Deposits))
    One customer can have - >Only one checking account only one Saving account, but can have many FD account. How do we implement this using integrity constraints?
    CUSTOMER Table -> Cust_id(PK), Cust_name, Cust_phone, Cust_address
    ACCOUNT Table -> AccountNo, Acc_type,Cust_id
    Your answer is greatly appreciated.
    Thanks
    Sophy

    You may need to create a UNIQUE function based index. That would work for you.
    create table customer_1 (Cust_id integer primary key, Cust_name varchar2(100), Cust_phone number, Cust_address varchar2(100))
    create table account_1 (AccountNo integer primary key, Acc_type varchar2(100),Cust_id integer references customer_1(cust_id))
    create unique index account_idx on account_1 (cust_id, decode(acc_type,'CA',acc_type, 'SA', acc_type, 'FD', 'FD' || accountno))
    insert into customer_1 (cust_id, cust_name, cust_phone, cust_address) values (1, 'karthick', 0, 'x')
    insert into account_1 (accountno, acc_type, cust_id) values(1, 'CA', 1)
    insert into account_1 (accountno, acc_type, cust_id) values(2, 'SA', 1)
    insert into account_1 (accountno, acc_type, cust_id) values(3, 'FD', 1)
    insert into account_1 (accountno, acc_type, cust_id) values(4, 'FD', 1)
    insert into account_1 (accountno, acc_type, cust_id) values(5, 'FD', 1)
    /

  • Mapping a one to many relationship using fluent api

    Hi I can't map my domains to match the database, since database is already created, I can't create or remove any other extra table.
    Database
    CREATE TABLE PLAYER (Id Int, Name varchar(100), PRIMARY KEY (Id))
    CREATE TABLE POSITION (Id Int, Name varchar(100), PRIMARY KEY (Id))
    CREATE TABLE CHAMPIONSHIP (Id Int, Name varchar(100), PRIMARY KEY (Id))
    CREATE TABLE RELATED (PlayerId Int, PositionId Int, ChampionshipId int,
    FOREIGN KEY (PlayerId) references PLAYER(id),
    FOREIGN KEY (PositionId) references POSITION(id),
    FOREIGN KEY (ChampionshipId) references CHAMPIONSHIP(id),
    CONSTRAINT AK_RELATED UNIQUE(PlayerId,PositionId,ChampionshipId))
    Domains:
    public class Player
    public Player()
    this.Relateds = new List<Related>();
    public int Id {get;set;}
    public string Name { get; set; }
    public virtual ICollection<Related> Relateds { get; set; }
    public class Position
    { public int Id {get;set;}
    public string Name { get; set; } public virtual ICollection<Related> Relateds { get; set; }
    public class Championship
    { public int Id {get;set;}
    public string Name { get; set; } public virtual ICollection<Related> Relateds { get; set; }
    public class Related
    public int PlayerId { get; set; }
    public Player Player{ get; set; }
    public int PositionId { get; set; }
    public Position Position { get; set; }
    public int ChamionshipId { get; set; }
    public Championship Championship { get; set; }
    FLUENT API:
    modelBuilder.Entity<Player>().HasKey(m => m.Id);
    modelBuilder.Entity<Player>().Property(m => m.Name).IsRequired();
    modelBuilder.Entity<Position>().HasKey(m => m.Id);
    modelBuilder.Entity<Position>().Property(m => m.Name).IsRequired();
    modelBuilder.Entity<Championship>().HasKey(m => m.Id);
    modelBuilder.Entity<Championship>().Property(m => m.Name).IsRequired();
    Seed.cs
    public DbSet<Player> Players { get; set; }
    public DbSet<Position> Positions { get; set; }
    public DbSet<Championship> Championships { get; set; }
    private void Seed2(ApplicationDbContext context)
    string[] playerNames = new string[] { "Adam", "John", "Lucas" };
    string[] positionNames = new string[] { "Sniper", "Camper", "Assalt" };
    string[] championshipNames = new string[] { "BF4", "CS1.6", "TF2" };
    int relations = 3;
    try
    foreach (var name in playerNames)
    if (!this.Players.Any(m => m.Name == name))
    Player player = new Player { Name = name };
    context.Players.Add(player);
    foreach (var name in positionNames)
    if (!this.Players.Any(m => m.Name == name))
    Position position = new Position { Name = name };
    context.Positions.Add(position);
    foreach (var name in championshipNames)
    if (!this.Championship.Any(m => m.Name == name))
    Championship championship = new Championship { Name = name };
    context.Championships.Add(championship);
    context.SaveChanges();
    for (int i = 1; i <= relations; i++)
    var player = context.Players.ToList()[i];
    var position = context.Positions.ToList()[i];
    var championship = context.Championships.ToList()[i];
    if (!context.Relateds.Any(m =>
    context.Players.Any(t => m.PlayerId == t.Id)
    && context.Positions.Any(t => m.PositionId == t.Id)
    && context.Championships.Any(t => m.ChampionshipId == t.Id)))
    Related related = new Related
    Player = player,
    Position = position,
    Championship = championship
    player.Relateds.Add(related);
    context.Entry(player).State = EntityState.Modified;
    context.SaveChanges();
    catch (Exception ex)
    throw;
    I'm not able to insert into the Related table, I think the fluent api is not maped well, how can I fix it?

    Hello,
    >>I'm not able to insert into the Related table, I think the fluent api is not maped well, how can I fix it?
    As you mentions, your database already exists, so I assume that you are using database first approach, then, as far as I know, the fluent API is made only for Code-First approach and we don't need the fluent API if we create your model via Database-First.
    For database first approach, we just need to import existed tables to the designer surface by “Update Model From Database”. And with your provided model, I noticed that the related table does not contain a primary constraint, in Entity Framework, a table
    without the primary key would be treated as a view that is read only. So please create a primary constraint for the related table as:
    CREATE TABLE RELATED (PlayerId Int, PositionId Int, ChampionshipId int,
    FOREIGN KEY (PlayerId) references PLAYER(id),
    FOREIGN KEY (PositionId) references POSITION(id),
    FOREIGN KEY (ChampionshipId) references CHAMPIONSHIP(id),
    PRIMARY KEY CLUSTERED (PlayerId ASC, PositionId ASC,ChampionshipId asc),
    CONSTRAINT AK_RELATED UNIQUE(PlayerId,PositionId,ChampionshipId))
    With your provided tables, after adding this constraint, the Related table could add a new row as:
    using (DFDBEntities db=new DFDBEntities())
    RELATED related = new RELATED() { PlayerId = 1, ChampionshipId = 1, PositionId = 1 };
    db.RELATEDs.Add(related);
    db.SaveChanges();
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Using translate function for one to many character translation

    Hi friends!
    Can anybody tell me whether it is possible to use built in translate function for converting some text from a one alphabet to another one, if these alphabets are of different length. Something like
    SELECT TRANSLATE('текст',
    'АБВГДЕЕЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯ',
    'ABCGDEF"*GH*"HIJKLMNOPQRSTYVWXYZ') FROM dual;
    Or there is another function for this, or it is impossible?
    Thanks

    Hi,
    Maybe you could use REPLACE just once, and then TRANSLATE the rest?
    Something like:
    SELECT TRANSLATE(REPLACE('ABcDE', 'c', 'xz'),
                     'ABCDE',
                     'abcde')  from dual;
    TRANSLATE(REPLACE('ABCDE','C','XZ'),'ABCDE','ABCDE')
    abxzde                                             
    1 row selected.Regards
    Peter

  • Sql squery for one to many relationship

    I need to write sql for below requirement:
    table structure is
    serial no LPN
    1 4
    2 4
    3 6
    4 6
    5 6
    6 3
    7 3
    8 3
    9 1
    I have to pick distinct 'LPN' like below:
    (any serial no can be picked for the distinct LPN)
    results needs to be as below:
    serial no LPN
    1 4
    3 6
    6 3
    9 1
    Please suggest with sql.

    Hi,
    915766 wrote:
    I need to write sql for below requirement:
    table structure is
    serial no LPN
    1 4
    2 4
    3 6
    4 6
    5 6
    6 3
    7 3
    8 3
    9 1
    I have to pick distinct 'LPN' like below:That sounds like a job for "GROUP BY lpn".
    (any serial no can be picked for the distinct LPN)It looks like you're displaying the lowest serial_no for each lpn. That's easy to do, using the aggregate MIN function.
    results needs to be as below:
    serial no LPN
    1 4
    3 6
    6 3
    9 1
    Please suggest with sql.Here's one way:
    SELECT    MIN (serial_no)   AS serial_no
    ,         lpn
    FROM      table_x
    GROUP BY  lpn
    ORDER BY  lpn     -- if wanted
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Expressions for one-to-many

    Trying to get a query to return all users that have a particular role. The roles are stored in a Vector populated by the Role object in the User object.
    I only get an exception because the SQL end with "...WHERE" so no condition is added to the statement...
    Where am i going wrong...?
    ///////BITS OF CODE/////////
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(User.class);
    //Role selection...
    ExpressionBuilder userExp = new ExpressionBuilder();
    userExp.anyOf("roles").get("rceRoleId").equal(role.getRceRoleId());
    query.setSelectionCriteria(userExp);
    ///// SQL THAT I WANT TO ACHIVE /////
    SELECT uri.uri_username
    FROM tdcr_user_roles urs, tdcr_user_info uri, tdcr_role_code tdc
    WHERE ( (uri.uri_userid = urs.urs_uri_userid)
    AND (tdc.rce_role_id = urs.urs_rce_role_id)
    AND (tdc.rce_role_id = 1)
    Thanks!

    Jan,
    You are passing the ExpressionBuilder into the selection criteria and not the expression you created. The ExpressionBuilder is basically a factory for expressions.
    Try:
    ///////BITS OF CODE/////////
    ReadAllQuery query = new ReadAllQuery();
    query.setReferenceClass(User.class);
    //Role selection...
    ExpressionBuilder eb = new ExpressionBuilder();
    Expression userExp = eb.anyOf("roles").get("rceRoleId").equal(role.getRceRoleId());
    query.setSelectionCriteria(userExp);
    Doug

Maybe you are looking for