Fornax-Platform
Forum

Re: [Sculptor] uni-directional one-to-many mapping?

by deepshar027 :: Rate this Message:

Reply to Author | View in Thread

Hey Patrick,

I am facing this problem.

Consider this..similar like your example.

Entity Inventory{
  - List<@Item> items
}
Entity Item{
}

This generates an additional table INVENTORY_ITEM which I dont want (many-2-many relationship.)
I want to have unidiretional relationship(one-2-many) as only inventory can have items.

Now If I do the following

CASE:1

Entity Inventory{
  - List<@Item> items inverse
}

I see a reference of INVENTORY in item table which is not expected.
CREATE TABLE ITEM (
  ITEM_ID NUMBER(20) NOT NULL,
  INVENTORY NUMBER(20)  ,
);

What I want to have is just below and there should no reference of Inventory in Item table.

CREATE TABLE INVENTORY (
     INVENTORY_ID NUMBER(20) NOT NULL,
     ITEM_ID NUMBER(20) NOT NULL,
)

CASE 2:

I did the following(Not sure why but I read somewhere that inverse creates a reference in the child table)
As such the following doesnt look correct to me but still I tried

Entity Inventory{
 }
Entity Item{
    - List<@Inventory> inv inverse
}

It does this which seems okk...although it creates this INV_INDEX(INTEGER) which I'll have to fix somehow to make NUMBER

CREATE TABLE INVENTORY (
  INVENTORY_ID NUMBER(20) NOT NULL,
  INV_INDEX INTEGER(10),
  ITEM NUMBER(20)            
);

This is fine so far....but in Item.hbm.xml I see
<list name="inv">
      <key column="ITEM"/>  
      <index column="INV_INDEX"/>  
      <one-to-many class="com.bookonz.inventory.domain.Inventory"/>
    </list>  

I am not sure if this is correct? Should Item.hbm hold a reference to Inventory?


Please provide your inputs on this.

Thanks,
Deepak.


Do you need something like this, i.e. Moon doesn't refer back to Planet?

Entity Planet {
   - @Set<Moon> moons
}

Entity Moon {
}


This will result in a uni-directional many association, but will be implemented in the database as many-to-many.

To implement it with an ordinary foreign key in the child table you have to add inverse

Entity Planet {
   - @Set<Moon> moons inverse
}

Doc: http://www.fornax-platform.org/cp/display/fornax/3.+Advanced+Tutorial+(CSC)#3.AdvancedTutorial(CSC)-AdditionalReferenceFeatures

/Patrik

polly.c.chang wrote:
Hi,

Is it possible to map a uni-directional one-to-many mapping?  From looking at the documentation and template code, it looks like one has to mark the Reference as "inverse", which is a bi-directional mapping.  I just want to have a simple uni-directional mapping.

Thanks!
--Polly

 « Return to Thread: [Sculptor] uni-directional one-to-many mapping?