Bug 21 : @MapKey not used on Save
Priority 
Medium
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
0.9.3
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
10/07/2007
Updated 
10/07/2007
Type 
Bug
 
Attachments 
No attachments

When a @OneToMany is of type Map and it has a @MapKey set this property is not automatically set when the map is saved via a cascade.

public class CommentLink {
...
    @OneToMany(cascade=CascadeType.ALL)
    @MapKey(name="title")
    Map comments;

In the below code.. the title is used in the key of the Map but it is not automatically set against the bean, and in the database can end up as null.

User u = (User)Ebean.getReference(User.class, 1);
		
CommentLink cl = new CommentLink();
cl.setLinkUrl("http://none");
		
Comment cm = new Comment();

// without this set... title can be null
//cm.setTitle("kumera");

cm.setBody("body2");
cm.setUser(u);
		

Map comments = new LinkedHashMap();
// title not automatically set from the key value
comments.put("kumera", cm);

cl.setComments(comments);

Ebean.save(cl);
 
Rob 10 Jul 20:40
the fix...

The fix is to take the Map key value... and set it to the mapKey bean property when the beans are saved (via cascade).

So in the example, the value 'kumera' is set (automatically) to the title property of the child bean when it is saved. Note that this only occurs on save cascade.

Rob 10 Jul 20:40
fixed in 0.9.3

Fixed in 0.9.3

woResponse

Upload a file