Hibernate: How to persist Class that contains Map<String, List<String>> -


I want to continue the following class with 'bar'

 square fu {map & lt; String, list & lt; String & gt; & Gt; times; // ... // Other stuff .....} 

How can I do this in hibernate? If possible, how to do it with annotation in hibernate?

Oh, the nature of the map key string is that the smallest number (5-40) of them is, and they are Fu examples. The strings in the list are unique between both the list and the examples of Phu.

Thanks

Neither string nor entity, You should create a wrapper class which captures your list

Do not forget the setter

  @Antity Public Square Fu {Private mutableInt id = New MutableInt (); Private map & lt; String, customlist & gt; CustomListMap = NewHashet & lt; String, customlist & gt; (); Get @ID @ Generated Values ​​Public Integer () {return.id.intValue (); } Public Zero Set ID (integer ID) {return.id.setValue (id); } @OneToMany @MapKey (name = "key") Public map & lt; String, customlist & gt; GetCustomListMap () {Returns customListMap; } // Feature Feature Public Zero AdBar (String Key, String Bar) {CustomListMap.get (Key) == blank) Custom Listspap.Point (key, new customlist (new customlist ID (ID, key)); CustomListMap Add .getBar () (bar).}}  

and do not forget your custom customlist (Setter)

@Entity Public Category customists {Private custom ID ID custom list ID; Private list & lt; string & gt; bar; Private st Ing key; @ embedded ed public customist eyed customist list (return) {return custom list id;} @column (insertable = false, updatable = false) public string getKey () {return this.key;} @ Collection of Elements @ JoinTable (name = "Bar") Public list & lt; string & gt; GetBar () {return.bar;} @ Embedded Public Static Class Custom ListID Serializable {Private mutableInt fooId = new MutableInt ()) applies; Private string key; // Required A-User Contributor Public Customlist () {} Public Castlist (MutableInt fooId, String Key) {this.fooId = fooId; this. Key = key; } Public Integer getFooId () {return fooId.intValue (); } Public Zero Setfuid (Integer Fooid) {this.fooId.setValue (fooId); } // Gestures and Setter's Public Bullion Equal (Object O) {If (! (For example, Custom ListID)) returned incorrectly; Custom List ID Other = (customlist) o; New Axles Builder () Come back. Appendix (getFooId), Other.GetFuID () .Append (getKey), OtherGetke ()) .isEquals (); } // apply the hash code}}

You can also create a custom method that getBar which transparently encapsulates your custom list map as follows

  @interity public class fu {... public map & lt; String, list & lt; String & gt; & Gt; GetBar () {Map & Lieutenant; String, list & lt; String & gt; & Gt; Bar = new hashmop & lt; String, list & lt; String & gt; & Gt; (); For (entry & lt; string, customlist & gt; E: custom listspip), bar.put (e.getKey (), e.getValue (). GetBar ()); Return times; }}  

Comments