-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping a special ManyToMany relationship
PostPosted: Wed Jul 05, 2006 11:17 am 
Beginner
Beginner

Joined: Wed Mar 22, 2006 4:33 am
Posts: 20
Location: Berlin, Germany
Imagine the following ER Model:

Code:
-------             ---------------             ---------
|order|             |order_product|             |product|
--------(1..N)--(1)-----------------(1)--(1..N)----------
|id   |             |quantity     |             |id     |
|...  |             |             |             |name   |
-------             ---------------             ---------


This translates to the following tables in a relational database:

Code:
create table order(
  id integer not null,
  primary key(id)
)

create table product(
  id integer not null,
  name varchar(255) nut null,
  primary key(id)
)

create table order_product(
  order_id integer not null,
  product_id integer not null,
  quantity integer not null,
  foreign key(order_id) references order(id),
  foreign key(product_id) references product(id),
  primary key(order_id,product_id)
)


I now want to access the products with their corresponding quantity directly from the Order class using a Map:

Code:
class Order {
  int id;
  Map<Product, Integer> products = new HashMap<Product, Integer>;
...
}


The products Map shall contain the products of this order as its keyset and the quantity shall by the corresponding value.

How do I realize this with Hibernate without having to explicitly map the order_product table and without having a Set of OrderProducts in Order? Is this possible at all?

Uli


Top
 Profile  
 
 Post subject: answer?
PostPosted: Thu Jul 27, 2006 12:06 pm 
Newbie

Joined: Fri Feb 24, 2006 2:00 pm
Posts: 4
did you find an answer to this? i'm trying to solve the same problem, and would love to see a solution.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.