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);
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.
Fixed in 0.9.3