0

Is there any posibility to do something like this. I've got two entities: Item and Holder. I need to join Holder to item, to get hashmap:

HashMap> items = new HashMap>();

Key in this hashmap - value of name column. Object with the same name are grouped in List and joined by itemId

class Item {
  long id,
  String name
}

class Holder {
  long itemId
  HashMap<String,List<Item>> items = new HashMap<String,List<Item>>();
}

Any idea?:) Thanks for help ;)

mfijalek
  • 1
  • 1
  • Do you want to do it with hibernate only or do you want to do it by writing some source code? – TerenceJackson Sep 20 '13 at 13:02
  • The best it'll be if it'll be possible with clear hibernate annotations. I read something about it and i think its possible but i cant handle this. Maybe somebody do something like this – mfijalek Sep 20 '13 at 13:04
  • I do not know if it is possible with hibernate, but you can have a look here: http://stackoverflow.com/questions/4700150/how-to-persist-a-hashmap-with-hibernate. In my opinion you have a 1:n relationship between Holder and Item. The representation as an hierarchie (HashMap) has nothing to do with the database design and I think it would be better not to calculate the hierarchie in the source code. – TerenceJackson Sep 20 '13 at 13:07
  • If holder contains multiple items then why do you have itemId in holder ? Just trying to understand entity model. – Sachin Thapa Sep 20 '13 at 14:07
  • model is different, by i create model for this case :) i cant paste original code, becouse is some part of company code. instead of itemId in holder simple id :) – mfijalek Sep 23 '13 at 09:04

0 Answers0