springcorn
springcorn

Reputation: 631

hibernate mapping where you have a Map of Lists

Is there a way to create a hibernate mapping where you have a Map of Bags or Sets or some type of collection?

For instance, maybe I have an inventory of parts and I want to pull them into a Map like so:

   Map<PartType, List<Part>> inventory;

So PartType which might be a class or just a String is the map key.

Thanks for the input!

Upvotes: 3

Views: 1044

Answers (2)

overmeulen
overmeulen

Reputation: 1158

No you can't, you need to create an intermediate class that contains the List. Your map will become :

Map<PartType, Parts> inventory;

And you need to create a new class with its own mapping :

public class Parts {

   private List<Part> parts;

}

Upvotes: 2

Suresh Atta
Suresh Atta

Reputation: 121998

IMO it should be an Id of PartType pojo

<map name="mymap" cascade="all">
         <key column="parttype_id"/>
            .
            .
            .

      </map>

Upvotes: 0

Related Questions