Unidirectional Relationship

Hello,
I'm interested in creating a new unidirectional relationship, in IT1001, between a position (S) and a person (P) in order to reflect an employee's assignment to special positions (it is not the regular assignment described by relationship A/B 008).
I'm totally aware of the steps to create a new relationship, but when doing so the system automatically creates both the A and B relations, although I'm interested only in one relation only (a unidirectional relationship).
Is it possible? And if so, how can it be configured?
Thank you for the assistance
Liran
Edited by: Liran Azury on Mar 31, 2010 2:56 PM

Hi,
Sorry,I wrote it wrongly that my bean A is having local interface.Actually my entity bean B is having a local interface while bean A has a remote interface and the relationship is from Bean A to Bean B with navigation arrow on bean B.Also I have get method in bean B that returns reference of bean A and a set method that takes reference of bean A as an arg.

Similar Messages

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

  • Bidirectional and unidirectional relationship

    What is the difference between bidirectional and unidirectional relationship. it is confusing for me. to me all the relationship seems to be the bidirectional.
    thanx
    can somebody explain

    If you need to have a child object know about the parent then you use bi-directional otherwise a uni-directional relationship is from the Parent to the Child
    So a Purchase Order holds a list of Line Items, each Line Item references a Product Code
    There will be a Bi-Directional relationship between the Purchase Order & the Line Items but ONLY a uni-directional relationship between the Line Item & a Product Code
    ie you may want to obtain a list of Purchase Orders then navigate to the Line Items. From these you may want to be able to refer back to the PO

  • How can I establish many to many unidirectional relationship?

    Hi, EJB Fans!
    I am an ejb fan too.
    This time I am learn ejb2.0 and find very funny in cmr. I think it is a good idea and can do manythings we cann't do or difficult with ejb1.1.
    But in many to many relationship, I don't know how to give my tables to entity A and entity B. How can I define tables to make A contains related Bs' information? And so do B. But i think make this table is difficult, because we don't know exactly how many should contains? And this is an examples:
    Difine entity A as User, and B as roles such as Administration, user, power user, as we often used in network. A user can have many roles, and roles can allocated to many roles.
    Another examples is entity A as person, and B as Department. B container A, and A can join many department as he or she can.
    B can find A(s) with which clues?? Methods like this java.util.Collection getAs()
    , this collection how can ejb container caculate it out?
    It is very myth, even wonderful!
    I love java and more like ejbs.

    No body reply.
    My question is silly or my english is very bad.
    Sorry I am chinese-speaking programmer.

  • Unidirectional one-to-many relationship without a join table

    Hello,
    I have 2 classes, Invoice and InvoiceLine, and a one-to-many unidirectional relationship from Invoice to InvoiceLine. By default, with JPA, it would be mapped by a join table with foreign keys that refer to the 2 tables which represent Invoice and InvoiceLine.
    My problem: the database has already a foreign key in the table which represents InvoiceLine that refers to the table which represents Invoice.
    To solve my problem I could make the relationship bidirectional but I would like to know if it is possible to keep it unidirectional and to use the foreign key which already exists (in the table that represents InvoiceLine). How could I declare the mapping with JPA?
    Thanks in avance for your answers.

    JPA requires that any @OneToMany mapping not using a join table have an inverse @ManyToOne mapping. In general the foreign key in the target object needs to be mapped and a @ManyToOne mapping is normally the best way to map it, so making the relationship bi-directional is your best option.
    There are other ways in TopLink to map a unidirectional 1-m, but these are not directly supported by the JPA spec. You could define a TopLink OneToManyMapping for the relationship through a TopLink DescriptorCustomizer and the code API. You would still need to map the foreign key in the target object some way, but you could use a @Basic mapping for this as long as you keep it in synch.
    In TopLink you could also map the relationship using an AggregateCollectionMapping (basically a collection of embeddables), and then not require mapping the foreign key in the target, but this imposes limitations on the target object (must be treated like an embeddable instead of entity). You would also need to configure the target object to be an aggregateCollectionDescriptor if using this option.

  • Problem in mapping 1:M relationship

    I am using toplink+jpa in my application.
    I have a 1:M unidirectional relationship (without association table) in my application.
    I am not able to find correct annotations to define it.
    Kindly help.
    Following code works when I use JPA+Hibernate but doesnot work for JPA+Toplink:
    @Entity
    @IdClass(PersonPK.class)
    public class Person {
    /* to store the age*/
    private int age;
    /* to store the firstName*/
    @Id
    @Column(name="fname")
    private String firstName;
    /* to store the lastName*/
    @Id
    @Column(name="lname")
    private String lastName;
    /* to store the addressList*/
    @OneToMany(cascade = CascadeType.ALL)
    @JoinColumns({
    @JoinColumn(name="_fname", referencedColumnName="fname"),
    @JoinColumn(name="_lname", referencedColumnName="lname")
    private List<Address> addressList;
    public PersonPK getPersonPK() {
    return new PersonPK(this.firstName, this.lastName);
    public void setPersonPK(PersonPK personPK) {
    this.setFirstName(personPK.getFirstName());
    this.setLastName(personPK.getLastName());
    /* @return Returns the age */
    public int getAge() {
    return age;
    /* @param the age to set */
    public void setAge(int age) {
    this.age = age;
    /* @return Returns the firstName */
    public String getFirstName() {
    return firstName;
    /* @param the firstName to set */
    public void setFirstName(String firstName) {
    this.firstName = firstName;
    /* @return Returns the lastName */
    public String getLastName() {
    return lastName;
    /* @param the lastName to set */
    public void setLastName(String lastName) {
    this.lastName = lastName;
    /* @return Returns the addressList */
    public List getAddressList() {
    return addressList;
    /* @param the addressList to set */
    public void setAddressList(List addressList) {
    this.addressList = addressList;
    Thanks

    The JPA 1.0 spec explicitly states that doing this kind of thing is not portable, and in general is not a good object model design to match the relational schema.
    It is recommended that if a foreign key to another table exists in an entity row that there be a relationship from the entity to the corresponding entity of the target table, or that a join table be used.

  • OneToMany Unidirectional strange behavior ?

    I am implementing hibernate with JPA annotations and trying to do a very simple thing but seeing very different behavior in oracleAS.
    I have an Order object which has many OrderLineItems and i want a unidirectional relationship NOT A BIDIRECTIONAL.
    When i try the following code with a main method, it does work perfectly fine, but the same code when deploying to Oracle Application server in a session bean it fails with the following exception
    Exception Description: @OneToMany for attribute name [orderLineItemsList] in entity class [class com.thoughtclicks.domains.Orders] should not have @JoinColumn(s) specified. In the case where the @OneToMany is not mapped by another entity (that is, it is the owning side and is uni-directional), it should specify (optional through defaulting) a @JoinTable.
    Below is the defination of Order Object: and as it is unidirection there is no code for order in orderlineitems
    @OneToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
    @JoinColumn(name="ORD_ID")
    public List<OrderLineItems> getOrderLineItemsList() {
    return orderLineItemsList;
    Does anybody know what can be the issue with the oracle as deployment ?
    Message was edited by:
    rahul_juneja

    Guys,
    Any Clues about this ?
    Thanks,
    Rahul

  • Qtn on relationships

    Hi,
    Why is the relation A011 oneway? Why does't it have a reciporcal relationship?
    Can anyone give more examples of such unidirectional relationships?
    thanks in advance...
    Sashi

    Check this link
    http://help.sap.com/erp2005_ehp_03/helpdata/EN/66/9bb2b43aff11d189370000e829fbbd/frameset.htm
    Hope will get u some idea

  • @OneToOne Unidirectional Annotation on @Id (Problem?)

    I am working with a @OneToOne Unidirectional Relationship that is
    defined as the SessionsLendee Entity pointing towards the Leads Entity
    (i.e. there can't be the existance of Leads without SessionsLendee,
    otherwise stated, there can't be a lead without a lendee session
    creating it first). So, My problem is the following: When I add the {color:#ff0000}@OneToOne{color}
    annotation to the SessionsLendee class, my IDE throws an error that
    "There is no ID defined for this entire entity hiearchy". For some
    reason, there is a problem with my IDE recognizing the @Id annotation when I add the @OneToOne annotation to the field. Thanks in advance for your help!
    public class SessionsLendee implements Serializable {
    *@Id*
    *@GeneratedValue(strategy = GenerationType.IDENTITY)*
    *{color:#ff0000}@OneToOne{color}*
    *@JoinColumn(name="session_lendee_id")*
    protected long session_lendee_id;
    public SessionsLendee() {}
    public abstract class Leads implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="lead_id")
    protected long lead_id;
    *@Column(name="session_lendee_id")*
    protected long session_lendee_id;
    public Leads() {}
    }

    Thank you. This definately is a work around the problem. Anyway, since a lead can't exist without the lendee session, it is probably more appropriate to have the @OneToOne annotation on a lead_id field within the SessionsLendee entity anyway. Thank you for your time in responding.

  • Heap Exhaustion Exception for One-to-One Unidirectional

    Using Glassfish 2.1 with TopLink, EJB3 and JPA in WinXP SP2 environment. Am observing heap exhaustion exceptions apparently whenever an entity references a different entity via a one-to-one unidirectional relation.
    Have resolved two heap exhaustion exception problems but have one more remaining.
    The first heap exhaustion problem occurred when entity "A" declared a one-to-many relationship with entity "B", and entity "B" declared a many-to-one relationship with entity "A". But entity "A" also erroneously declared a one-to-one unidirectional relationship with entity "B". As soon as entity "A" had an entity "B" inserted into it, a heap exhaustion exception occurred when entity "A" was serialized in a return statement. As soon as the erroneous one-to-one unidirectional relationship was removed from entity "A", the heap exhaustion exceptions ceased.
    The second heap exhaustion problem occurred when the same entity "A" mistakenly declared a one-to-one unidirectional relationship with entity "C", and entity "C" correctly declared a many-to-one relationship with entity "A". Once again as soon as entity "A" had an entity "C" inserted into it, a heap exhaustion exception occurred when entity "A" was serialized in a return statement. As soon as the erroneous one-to-one was corrected to a one-to-many, the heap exhaustion exceptions ceased.
    But the third heap exhaustion problem occurs when the same entity "A" correctly declares a one-to-one unidirectional relationship with entity "D". As soon as entity "A" has an entity "D" inserted into it, a heap exhaustion exception occurs when entity "A" is serialized in a return statement. I cannot "fix" this as I did in the two above cases because this time the one-to-one unidirectional relationship is correct.
    Have one-to-one bidirectional relationships as well as one-to-many / many-to-one that do not trigger heap exhaustion exceptions when serialized in a return statement.
    Here is the Java code that declares the problem one-to-one bidirectional relationship in entity "A":
    @OneToOne(cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH }, optional=true, fetch=FetchType.LAZY)
    @JoinColumn(name="fk_asset_type_id", referencedColumnName="asset_type_id", updatable=false)
    public AssetType getAssetType() {
    return this.assetType;
    public void setAssetType(AssetType assetType) {
    this.assetType = assetType;
    Here is the SQL used to generate the table associated with entities "D" and "A":
    CREATE TABLE [dbo].[asset_type](
         [asset_type_id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
         [asset_name] [varchar](40) NULL,
         [asset_description] [varchar](50) NULL,
         [last_user] [varchar](50) NULL,
         [last_mod] [timestamp] NOT NULL,
    CONSTRAINT [PK_asset_type] PRIMARY KEY CLUSTERED
    ([asset_type_id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]
    GO
    CREATE TABLE [dbo].[server_asset](
         [server_asset_id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
         [nsn] [varchar](40) NULL,
         [gov_furnish_equip_asset_id] [varchar](255) NULL,
         [server_name] [varchar](255) NULL,
         [server_ip_addr] [varchar](255) NULL,
         [serial_nbr] [varchar](50) NULL,
         [outfitting_list] [text] NULL,
         [update_cst] [varchar](255) NULL,
         [update_pst] [varchar](255) NULL,
         [date_decommissioned] [datetime] NULL,
         [server_asset_org_date] [datetime] NULL,
         [server_asset_update_date] [datetime] NULL,
         [fk_manufacturer_id] [numeric](18, 0) NULL,
         [fk_trade_partner_id] [numeric](18, 0) NULL,
         [fk_asset_type_id] [numeric](18, 0) NULL,
         [fk_model_id] [numeric](18, 0) NULL,
         [fk_item_part_id] [numeric](18, 0) NULL,
         [fk_gold_disk_asset_id] [numeric](18, 0) NULL,
         [fk_jtdi_location_id] [numeric](18, 0) NULL,
         [last_user] [varchar](50) NULL,
         [last_mod] [timestamp] NOT NULL,
    CONSTRAINT [PK_server_asset] PRIMARY KEY CLUSTERED
    ([server_asset_id] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[server_asset] WITH CHECK ADD CONSTRAINT [FK_server_asset_asset_type] FOREIGN KEY([fk_asset_type_id])
    REFERENCES [dbo].[asset_type] ([asset_type_id])
    GO
    Have been batting this issue around on the Manning Panda forum. Consensus there is that the problem may be TopLink related. Would be most grateful for any suggestions. The easy way out would be to change the one-to-one unidirectional to bidirectional but don't want to do that unless there is no alternative. Thanks.

    Looking at the stack trace (found in your post on the GlassFish forum) it appears to be an issue with corba serialization in the container. I found this bug, https://glassfish.dev.java.net/issues/show_bug.cgi?id=2693 in which the stack looks almost identical to yours.
    The only way that I think TopLink could be involved is that TopLink is weaving your code, and potentially so is corba. You can try turning off weaving to see if that 'solves' your problem. (Note: I am not confidant that this will work, but I notice that the corba stack may be doing some weaving of it's own.)
    The persistence unit property is toplink.weaving. Setting it to false will turn off TopLink weaving.
    <property name="toplink.weaving" value="false"/>

  • ManyToOne relationship with extra field in the joinTable

    Hi,
    I wanted to make a ManyToMany unidirectional relationship using these two entities.
    Invoice (id)
    Product (id, price)
    The problem is that I want in the resulting joinTable another field named QUANTITY
    I don’t think there is a way to obtain a join table with an extra field from a ManyToMany relationship, am I right ?
    Si I decided to add an InvoiceLine table
    With Invoice and InvoiceLine tables having a OneToMany unidirectional relationship.
    And InvoiceLine and Product tables having a ManyToOne unidirectional relationship.
    This is the code I made
    import java.util.Set;
    import java.util.HashSet;
    import javax.persistence.*;
    @Entity
    public class Invoice implements java.io.Serializable {
         private long id;
         private Set<InvoiceLine> InvoiceLines = new HashSet<InvoiceLine>();
         @Id
         @GeneratedValue
         public long getId() {
              return id;
         public void setId(long id) {
              this.id = id;
         @OneToMany(cascade={CascadeType.ALL})
         @JoinColumn(name="INVOICE_ID")
         public Set<InvoiceLine> getInvoiceLines() {
              return InvoiceLines;
         public void setInvoiceLines(Set<InvoiceLine> InvoiceLines) {
              this.InvoiceLines = InvoiceLines;
    import javax.persistence.*;
    @Entity
    public class InvoiceLine implements java.io.Serializable {
         private long id;
         private Product product;
         private int quantity;
         @Id
         @GeneratedValue
         public long getId() {
              return id;
         public void setId(long id) {
              this.id = id;
         @ManyToOne
         public Product getProduct() {
              return product;
         public void setProduct(Product product) {
              this.product = product;
         public int getQuantity() {
              return quantity;
         public void setQuantity(int quantity) {
              this.quantity = quantity;
    import javax.persistence.*;
    @Entity
    public class Product implements java.io.Serializable {
         private long id;
         private double price;
         public Product() {
         public Product(double price) {
              this.price = price;
         @Id
         @GeneratedValue
         public long getId() {
              return id;
         public void setId(long id) {
              this.id = id;
         public double getPrice() {
              return price;
         public void setPrice(double price) {
              this.price = price;
    }The problem is that I want the InvoiceLine table to have a composite primary key (from the two foreign keys in the table invoice_id and product_id).
    Can anyone tell me how I can do this.
    Thanks.
    Edited by: Exhortae on Jun 23, 2009 4:59 PM
    Edited by: Exhortae on Jun 23, 2009 5:01 PM

    Hello,
    If we create a Z report for this program, can anyone please tell me where can I find the function "REUSE_ALV_GRID_DISPLAY" in the given program so that I can add my fields along with the default filelds displayed...
    Thanks
    ~Him

  • Bug - multiple related instances of same class

    We've discovered a rather subtle bug in the process by which Kodo
    searches for reachable related objects to persist. If an instance of a
    PC class (A) has two relationships to the same PC class (B), and both
    related instances of B have the same value for their PK-field, then only
    one of the related instances of B will be persisted.
    Obviously, this problem only occurs in the context of application
    identity. We've only encountered it when all the instances involved are
    newly created and being made persistent for the first time (else the
    instances would have different PK-values). It should also be noted that
    we're assigning PK-values in jdoPreStore(). Here's the specific
    situation we encountered:
    Class A has two relationships to class B, represented by fields "B b1"
    and "B b2". In our case, A.b1 is the many-side of a bidirectional
    one-to-many relationship; the one-side is implemented by a field "List
    aList" in B. A.b2 is the navigable side of a unidirectional
    relationship; there is no corresponding field in B. (We haven't checked
    whether or how the cardinality or navigability of the relationships
    affects the problem.)
    Let "a1" be the sole instance of A. If a1.b1 is set to an instance of B
    but a1.b2 is null, and makePersistent( a1 ) is called, then a1 and b1
    are persisted correctly and the relation field b2_id in TableA is NULL.
    However, if a1.b2 is set to a second instance of B and both instances of
    B have the same initial value of their PK-field, then a.b2 is not
    persisted. Only one record is added to TableB; it corresponds to A.b1.
    Interestingly, in this case the relation field b2_id in TableA is not
    NULL, but has the default value of b2's PK-field. jdoPreStore() is not
    called on b2 and b2 is not persisted, but its PK-field is read in the
    process of persisting a1.
    Since we've placed the jdoPreStore() callback in a common non-persistent
    adapter superclass, we're currently able to work around the problem with
    a static "seed" PK value that is incremented in the superclass default
    constructor to provide a unique initial value for each PK-field. If
    anyone would like the code for this approach we'll post it, although
    it'll become unnecessary when the problem is fixed.
    Jerry Pulley
    Sr. Developer
    Commerce Technologies, Inc.

    I'm curious what behavior, besides throwing an exception, could even be
    possible. If the pm discovers two object with the same id, it seems that it
    has to choose one of them to make persistent. How could it possibly resolve
    differences in the fields of the two instances in deciding which one is the
    correct one to put in the db? Additionally, allowing this behavior could
    lead to subtle, difficult to detect bugs in your program, since ( as Abe
    points out ) JDO promises that there will only be one instance of an object
    with a given primary key per PM. Other code may make decisions based on
    this expectation ( like refreshing one of the objects after making a change
    in a different PM ), that would lead to problems for code still hanging on
    to the second instance.
    IMHO, it should throw an exception.
    -Eric
    "Abe White" <[email protected]> wrote in message
    news:[email protected]...
    Thanks for the bug report! However, I'm not entirely sure that this is a
    bug (at least not the bug you think it is); either way it's an extremely
    interesting case. The reason I say it might not be a bug is thatassigning
    pk values in jdoPreStore seems suspect.
    We know that a single PM cannot at any time contain multiple instances
    with the same oid value, app id or otherwise. This is obvious from the
    getObjectById method -- only one object can have a particular oid.
    We also know that jdoPreStore is called only for instances managed by a
    PM (duh!).
    Thus it should not be possible to see a case where jdoPreStore is
    called for 2 objects with the same initial oid.
    Now, I realize that when you're dealing with persistence-by-reachability
    things become less clear. However, I think the general point stands: at
    the time that the objects are made persistent they all must have unique
    oid values, and objects must be made persistent before jdoPreStore is
    called.
    Technically we could get around this. The current
    persistence-by-reachability algorithm is something like:
    flushed = {}
    while flushed.size < persistent.size:
    for each persistent instance:
    if instance not in flushed:
    instance.jdoPreStore // may persist more instances
    instance.persistFirstClassFields // may persist more too
    flushed += instance
    In sum this is a breadth-first method of persisting relations. It could
    be changed to a depth-first system instead of persisting all first class
    fields each one is persisted and then immediately the algorithm is
    repeated for that object before the other fields are touched. However,
    this seems like it might lead to other unexpected behavior.
    Generally, it just seems like waiting till jdoPreStore to assign the oid
    of an object seems like a bad idea. I think the real bug is that Kodo is
    not throwing an exception as soon as 2 object with the same oid are
    detected (currently it just lets one overwrite the other in the cache,
    which results in the behavior you see).
    Does anyone else have an opinion on this? I'm certainly not fixed on my
    interpretation of things; if you disagree I'd be very interested in
    hearing other arguments.

  • Cmp-field is read-only

    Say I have beans A and B where A <- B (unidirectional relationship)
    and A.cmp_A and B.cmr_A point to same db field
    I try this and get exception as below while doing A.setCmp_A()
    javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapped
    to the same column, the setXXX method for the cmp-field may not be called. The
    cmp-field is read-only.
    the cmp-field and cmr-field are in separate beans.
    F1

    Say I have beans A and B where A <- B (unidirectional relationship)
    and A.cmp_A and B.cmr_A point to same db field
    I try this and get exception as below while doing A.setCmp_A()
    javax.ejb.EJBException: When a cmp-field and a cmr-field (relationship) are mapped
    to the same column, the setXXX method for the cmp-field may not be called. The
    cmp-field is read-only.
    the cmp-field and cmr-field are in separate beans.
    F1

  • Persisting Entities in different databases

    Hello! In our compony we need to store information in two different databases. To check if this is possible I've written a simple program, in which part of the entities is stored in one DB, and the other part - in another. And I have an error during deployment whith the following stack trace:
    Deployment Error -- Exception [TOPLINK-0] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.IntegrityException
    Descriptor Exceptions:
    Exception [TOPLINK-94] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DescriptorException
    Exception Description: Descriptors must have a table name defined.
    Descriptor: RelationalDescriptor(entity.Specification --> [])
    Exception [TOPLINK-74] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DescriptorException
    Exception Description: The primary key fields are not set for this descriptor.
    Descriptor: RelationalDescriptor(entity.Specification --> [])
    Exception [TOPLINK-108] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DescriptorException
    Exception Description: Cannot find value in class indicator mapping in parent descriptor [null].
    Descriptor: RelationalDescriptor(entity.Specification --> [])All I want is to store Specification entity and SalesLineItem entity in different databases, while there's a OneToOne unidirectional relationship between them. Here is part of SalesLineItem entity:
    @Entity
    public class SalesLineItem implements Serializable {
         private int quantity;
         private Specification productSpec;
         private int id;
         private Sale sale;
         @OneToOne
         public Specification getSpecification() {
              return this.productSpec;
         }And here's my persistence.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
      <persistence-unit name="pu1" transaction-type="JTA">
        <jta-data-source>jdbc/__default</jta-data-source>
        <class>entity.Payment</class>
        <class>entity.Sale</class>
        <class>entity.SalesLineItem</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
          <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
          <property name="toplink.platform.class.name" value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
        </properties>
      </persistence-unit>
      <persistence-unit name="pu2" transaction-type="JTA">
        <jta-data-source>jdbc/__resource</jta-data-source>
        <class>entity.Catalog</class>
        <class>entity.Specification</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
          <property name="toplink.ddl-generation" value="drop-and-create-tables"/>
          <property name="toplink.platform.class.name" value="oracle.toplink.essentials.platform.database.DerbyPlatform"/>
        </properties>
      </persistence-unit>
    </persistence>Then, I suppose, I create two EntityManger is session beans, each associated with one specific persistence unit.
    When I use one database (one pesistence-unit in persistence.xml), everything works fine. I wonder, if it's possible to persist entities in a such way that entities with relationships between them are stored in different databases. Any help is greatly appreciated.

    If I could know, how to perform or some sample code, for the following two steps it would be great.
    Write descriptor ammendment code to bind together that go from (A) to (B) and (B) to (A).
    Be sure to map the ammendment descriptors in the mapping workbench.Or please point me to the right toplink documentation or examples.
    Thanks a lot for your help.

  • CMR Many-to-Many Question

    Hi,
    I am doing an applicatiion using CMP. I have 2 tables in my database that have a many-to-many unidirectional relationship. Consequently, I have created a link table that takes the primary key value from both tables. It is the standard way for doing it in a relational databse. I have setup CMR fields in my appropriate bean class. My question is, will that link table be updated by the container when I create a new relationship?
    I have looked at the folowing code from the IBM website. I think it is a good example.
    The addRole() adds a role to a UserBean as follows:
    public void addRole(String email, String roleName){
        LocalUser user = userHome.findByPrimaryKey(email);
        LocalRole role = roleHome.findByPrimaryKey(roleName);
        Collection roles = user.getRoles();
        roles.add(role); The author the says "Thus, when a role gets added to the roles collection, the EJB container updates the datastore. Thus, the code that inserts the relationship in the datastore is the interface of the Collection class."
    Does he mean that a link table will be updated?
    If anyone has tried this could they please let me know.
    Thanks,
    Chris.

    Yeh I know I don't have to write to the database, but when I create my CMP bean I didnt map it to my link table. Therefore I'm not sure if the container will update the link table in my database.

Maybe you are looking for