-->
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.  [ 1 post ] 
Author Message
 Post subject: Map object that belongs to two other objects (ob
PostPosted: Sun Aug 22, 2010 4:20 pm 
Newbie

Joined: Sun Aug 22, 2010 4:16 pm
Posts: 2
I'm having a bit of trouble mapping the following:

Code:
public class Operation {
  private Integer id;
  private String name;
  private List<Item> items = new ArrayList<Item>();
  //set/getters/hashcode/etc. omitted

  public void addItem(Item i,Operation end) {
     i.setOperationStart(this);
     i.setOperationEnd(end};
     items.add(i);
     end.getItems().add(i);
   }

public class Item {
  private Integer id;
  private String name;
  private Operation  operationStart;
  private Operation  operationEnd;
  //set/getters/hashcode/etc. omitted
}


The tables I'd ideally like to map would be;
Code:
create table operation {
  id int primary key,
  name varchar(255) not null
)

create table item (
  id int primary key,
  name varchar(255) not null,
  operation_start int not null, -- foreign key to operation.id
  operation_end int not null, -- foreign key to operation.id
)


So basically an Operation have a bunch of Items, and an Item belongs to 2 Operations. Also, it doesn't make sense for an item to exist if one of the Operations doesn't exist, i.e. if I delete one of the Operations, I want to remove the item from wherever else it's stored as well.

Does anyone have a pointer on how I'd map the above classes, or could point me to some examples showing how to map a child object that has 2 parents ?


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

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.