What we want to do is a bit different from the standard way people use relational databases. The objects we want to store contains a [b]variable[/b] ammount of items in a collection and each item may be [b]one of several[/b] known objects. I already saw something similar on the forum posted by [sfarrel] and [dotski81]
We have
public class ItemContainer {
Long id;
ArrayList items;
...
public Long getId(){...}
public void setId(Long id){...}
public List getItems() {...}
public List setItems() {...}
}
Each item in the items list may now be one of several known classes e.g.
public class ItemTypeA {
Long id;
ItemContainer owner;
...
}
public class ItemTypeB {
Long id;
ItemContainer owner;
...
}
public class ItemTypeC {
Long id;
ItemContainer owner;
...
}
Two questions:
[b]1)[/b] How whould you recommend doing this in Hibernate? I think in the direction of letting ItemTypeA,B,C extends some base class ItemType and then use a normal <list> ...<one-to-many class="ItemType"/></list> mapping in the ItemContainer map.
[b]2)[/b] I also need to track history for every item change. Do I need to save a clone of every changed item in a seperate table or what is the best way to do it.
I just need some ideas. I'm sure someone else did something simmilar.
Thanks.
|