This is so basic use case that I feel embarrassed for having to ask this... but after hours of Googling, I was unable to find a single good example of this (though there must be many). So...I have a Play Framework 2.0.1 project with entities Page and Article. One page may have 0...n articles and article always has a reference to the page that contains it. When I retrieve data, everything works: pageObject.getArticles().size() returns the number of articles associated with the page. When I try to add a new article to a page, I get InvocationTargetException... and don't have any idea why that is.Here are the relevant parts of the code./* ARTICLE */@Entity@Table(name="articlemodule")public class ModuleArticle extends Model implements ModuleInterface{@Idpublic Long id;@ManyToOne@JoinColumn(name="pageId",referencedColumnName="id")public Page page;public static Finder<Long, ModuleArticle> find = new Finder<Long, ModuleArticle>(Long.class, ModuleArticle.class);public void setPage(Page page){this.page = page;}}/* PAGE */@Entity@Table(name="page")public class Page extends Model{@Idpublic Long id;@OneToMany(targetEntity=ModuleArticle.class,mappedBy="page")public Set<ModuleArticle> articles;public Set<ModuleArticle> getArticles(){return articles;}public static Finder<Long, Page> find = new Finder<Long, Page>(Long.class, Page.class);}/* CONTROLLER */public static Result addArticle(Long id, Long pageId){Page p = Page.find.byId(pageId);ModuleArticle ma = new ModuleArticle();ma.setPage(p);p.getArticles().add(ma); /* THIS LINE CAUSES ERROR */p.save();return ok("new size " + p.getArticles().size());}/* STACK TRACE */! @6b08fihim - Internal server error, for request [POST ***url removed*** ->play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[RuntimeException: java.lang.reflect.InvocationTargetException]]at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.1]at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.1]at akka.actor.Actor$class.apply(Actor.scala:311) [akka-actor.jar:2.0.1]at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.1]at akka.actor.ActorCell.invoke(ActorCell.scala:619) [akka-actor.jar:2.0.1]at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:196) [akka-actor.jar:2.0.1]Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetExceptionat play.db.ebean.Model._getId(Model.java:56) ~[play_2.9.1.jar:2.0.1]at play.db.ebean.Model.hashCode(Model.java:183) ~[play_2.9.1.jar:2.0.1]at java.util.HashMap.put(HashMap.java:389) ~[na:1.6.0_24]at java.util.HashSet.add(HashSet.java:217) ~[na:1.6.0_24]at com.avaje.ebean.common.BeanSet.add(BeanSet.java:207) ~[ebean.jar:na]at controllers.Module.addArticle(Module.java:207) ~[classes/:na]Caused by: java.lang.reflect.InvocationTargetException: nullat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_24]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.6.0_24]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.6.0_24]at java.lang.reflect.Method.invoke(Method.java:616) ~[na:1.6.0_24]at play.db.ebean.Model._getId(Model.java:52) ~[play_2.9.1.jar:2.0.1]at play.db.ebean.Model.hashCode(Model.java:183) ~[play_2.9.1.jar:2.0.1]Caused by: java.lang.NullPointerException: nullat models.ModuleArticle.getId(ModuleArticle.java:53) ~[classes/:na]at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_24]at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.6.0_24]at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.6.0_24]at java.lang.reflect.Method.invoke(Method.java:616) ~[na:1.6.0_24]at play.db.ebean.Model._getId(Model.java:52) ~[play_2.9.1.jar:2.0.1]
There is no cascade persist on page.articles ... So saving page does not cascade save the articles.
A good idea would be to have the transaction logging on do you can see more clearly what is happening.
Cheers, Rob.