Hi Deepak,

CASE2 is wrong way.

You have two options.
1) many-to-many join table. This is the default.
2) foreign key column in ITEM. This is the result of inverse keyword.

Alternative 2 is more efficient, but it introduces a dependency at the db
level from item to inventory, which is sometimes unwanted, especially when
inventory and item are in different modules.

I don't think you can design this in the database in any other way.

Below INVENTORY table will not be able reference several items for one
inventory.
CREATE TABLE INVENTORY (
     INVENTORY_ID NUMBER(20) NOT NULL,
     ITEM_ID NUMBER(20) NOT NULL,
)


/Patrik





deepshar027 wrote:
> 
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/-Sculptor--uni-directional-one-to-many-mapping--tp21445883s17564p23712478.html
Sent from the Fornax-Platform mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Fornax-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fornax-developer

Reply via email to