Hallo Wally,

I've changed the mapping into:
  <class-descriptor class="demo.myshop.model.ojb2.SellableItem">
        <extent-class class-ref="demo.myshop.model.ojb2.ServiceContract" />
        <extent-class class-ref="demo.myshop.model.ojb2.Product" />
  </class-descriptor>

  <class-descriptor
        class="demo.myshop.model.ojb2.ServiceContract"
        table="OJB_SELLABLEITEM">
                
        <field-descriptor
                name="itemId"
                column="ITEMID"
                jdbc-type="INTEGER"
                primarykey="true"
                autoincrement="true"/>  
                
        <field-descriptor
                name="ojbConcreteClass"
                column="CLASS_NAME"
                jdbc-type="VARCHAR"/>
                
        <field-descriptor
                name="description"
                column="DESCRIPTION"
                jdbc-type="VARCHAR"/>
        
        <field-descriptor
                name="price"
                column="PRICE"
                jdbc-type="INTEGER"/>
        
        <field-descriptor
                name="period"
                column="PERIOD"
                jdbc-type="INTEGER"/>

        <collection-descriptor
                name="suppliers"
                element-class-ref="demo.myshop.model.ojb2.Supplier"
                auto-retrieve="true"
                auto-update="true"
                indirection-table="OJB_SUPPLIER_ITEM">
                <fk-pointing-to-this-class column="ITEMID"/>
                <fk-pointing-to-element-class column="SUPPLIERID"/>
      </collection-descriptor>
   </class-descriptor>
   
   <class-descriptor
        class="demo.myshop.model.ojb2.Product"
        table="OJB_SELLABLEITEM">
                
        <field-descriptor
                name="itemId"
                column="ITEMID"
                jdbc-type="INTEGER"
                primarykey="true"
                autoincrement="true"/>  
                
        <field-descriptor
                name="ojbConcreteClass"
                column="CLASS_NAME"
                jdbc-type="VARCHAR"/>
                
        <field-descriptor
                name="description"
                column="DESCRIPTION"
                jdbc-type="VARCHAR"/>
        
        <field-descriptor
                name="price"
                column="PRICE"
                jdbc-type="INTEGER"/>
        
        <field-descriptor
                name="weight"
                column="WEIGHT"
                jdbc-type="INTEGER"/>
        <collection-descriptor
                name="suppliers"
                element-class-ref="demo.myshop.model.ojb2.Supplier"
                auto-retrieve="true"
                auto-update="true"
                indirection-table="OJB_SUPPLIER_ITEM">
                <fk-pointing-to-this-class column="ITEMID"/>
                <fk-pointing-to-element-class column="SUPPLIERID"/>
      </collection-descriptor>
   </class-descriptor>



But now I get an error when I store a supplier (primary key - error, pk not unique in 
OJB_SUPPLIER_ITEM, can't insert).
Transaction started


[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR: SQLException during the 
execution of the Update SQL query (for a demo.myshop.model.ojb2.Supplier): 
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Verletzung der PRIMARY 
KEY-Einschr�nkung 'PK_OJB_SUPPLIER_ITEM'. Ein doppelter Schl�ssel kann in das 
OJB_SUPPLIER_ITEM-Objekt nicht eingef�gt werden.
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Verletzung der PRIMARY 
KEY-Einschr�nkung 'PK_OJB_SUPPLIER_ITEM'. Ein doppelter Schl�ssel kann in das 
OJB_SUPPLIER_ITEM-Objekt nicht eingef�gt werden.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for 
JDBC][SQLServer]Verletzung der PRIMARY KEY-Einschr�nkung 'PK_OJB_SUPPLIER_ITEM'. Ein 
doppelter Schl�ssel kann in das OJB_SUPPLIER_ITEM-Objekt nicht eingef�gt werden.
        at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
        at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)

Some more ideas ???

Thanks,
Stephan








-----Original Message-----
From: Gelhar, Wallace Joseph [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 15, 2003 3:44 PM
To: OJB Users List
Subject: RE: Mapping problem


Hi Stephan,

OJB does not support class descriptor inheritance for <extent-class> elements.  Try 
moving your "common" fields from Sellable item into each of the concrete class 
descriptors and making Sellable item non-concrete (it is only an interface after all) 
such as:

<class-descriptor class="demo.myshop.model.ojb2.SellableItem" >
        <extent-class class-ref="demo.myshop.model.ojb2.ServiceContract"
/>
        <extent-class class-ref="demo.myshop.model.ojb2.Product" /> </class-descriptor>

Hope this helps.

Wally

-----Original Message-----
From: Stephan Wannenwetsch [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 15, 2003 4:16 AM
To: [EMAIL PROTECTED]
Subject: Mapping problem


Hallo,

I've got a problem retrieving objects from a m:n relationship:

Object model:

class Supplier;
=>Collection items;

Interface SellableItem;
=>Collection suppliers;

class Product implements SellableItem;
=> Collection suppliers;

class ServiceContract implements SellableItem;
=> Collection suppliers;

Of course there are some more attributes in each class with the corresponding getter 
and setters.

I use an itermediate table OJB_SUPPLIER_ITEM to realise the m:n relationship.

Every thing works fine coming from the supplier side and retriving the related items 
of a supplier but I'm not able to retrieve the related suppliers of an item.

I hope someone can help me.

Thanks, 
Stephan

Mapping:

  <class-descriptor
        class="demo.myshop.model.ojb2.Supplier"
        table="OJB_SUPPLIER">
        <field-descriptor
                name="fk_bpid"
                column="FK_BPID"
                jdbc-type="INTEGER"
                primarykey="true"
                autoincrement="false"
                access="anonymous"/>
                
        <field-descriptor
                name="shippingCost"
                column="SHIPPINGCOST"
                jdbc-type="INTEGER"/>
        
        <reference-descriptor
                name="businessPartner"
                class-ref="demo.myshop.model.ojb2.BusinessPartner">
                <foreignkey field-ref="fk_bpid"/>
        </reference-descriptor>
        
        <collection-descriptor
                name="items"
                element-class-ref="demo.myshop.model.ojb2.SellableItem"
                auto-retrieve="true"
                auto-update="true"
                indirection-table="OJB_SUPPLIER_ITEM">
                <fk-pointing-to-this-class column="SUPPLIERID"/>
                <fk-pointing-to-element-class column="ITEMID"/>
      </collection-descriptor>
      
  </class-descriptor>

  <class-descriptor
        class="demo.myshop.model.ojb2.SellableItem"
        table="OJB_SELLABLEITEM">
        
        <extent-class class-ref="demo.myshop.model.ojb2.ServiceContract"
/>
        <extent-class class-ref="demo.myshop.model.ojb2.Product" />
        
        <field-descriptor
                name="itemId"
                column="ITEMID"
                jdbc-type="INTEGER"
                primarykey="true"
                autoincrement="true"/>  
                
        <field-descriptor
                name="ojbConcreteClass"
                column="CLASS_NAME"
                jdbc-type="VARCHAR"/>
                
        <field-descriptor
                name="description"
                column="DESCRIPTION"
                jdbc-type="VARCHAR"/>
        
        <field-descriptor
                name="price"
                column="PRICE"
                jdbc-type="INTEGER"/>
        
        <collection-descriptor
                name="suppliers"
                element-class-ref="demo.myshop.model.ojb2.Supplier"
                auto-retrieve="true"
                auto-update="true"
                indirection-table="OJB_SUPPLIER_ITEM">
                <fk-pointing-to-this-class column="ITEMID"/>
                <fk-pointing-to-element-class column="SUPPLIERID"/>
      </collection-descriptor>
   </class-descriptor>

  <class-descriptor
        class="demo.myshop.model.ojb2.ServiceContract"
        table="OJB_SELLABLEITEM">
                
        <field-descriptor
                name="itemId"
                column="ITEMID"
                jdbc-type="INTEGER"
                primarykey="true"
                autoincrement="true"/>  
                
        <field-descriptor
                name="ojbConcreteClass"
                column="CLASS_NAME"
                jdbc-type="VARCHAR"/>
                
        <field-descriptor
                name="description"
                column="DESCRIPTION"
                jdbc-type="VARCHAR"/>
        
        <field-descriptor
                name="price"
                column="PRICE"
                jdbc-type="INTEGER"/>
        
        <field-descriptor
                name="period"
                column="PERIOD"
                jdbc-type="INTEGER"/>
   </class-descriptor>
   
   <class-descriptor
        class="demo.myshop.model.ojb2.Product"
        table="OJB_SELLABLEITEM">
                
        <field-descriptor
                name="itemId"
                column="ITEMID"
                jdbc-type="INTEGER"
                primarykey="true"
                autoincrement="true"/>  
                
        <field-descriptor
                name="ojbConcreteClass"
                column="CLASS_NAME"
                jdbc-type="VARCHAR"/>
                
        <field-descriptor
                name="description"
                column="DESCRIPTION"
                jdbc-type="VARCHAR"/>
        
        <field-descriptor
                name="price"
                column="PRICE"
                jdbc-type="INTEGER"/>
        
        <field-descriptor
                name="weight"
                column="WEIGHT"
                jdbc-type="INTEGER"/>
   </class-descriptor>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to