Hi,
I'm trying to automatically create a new object each time another
object is created. I decided to use @PostPersist annotation, here is
my code :
public class AdviceSheet extends GenericModel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int id;
public String title;
public String city;
@PostPersist
public void postPersist() {
System.out.println(this.description);
new City(this.city).save();
}
}
public class City extends GenericModel {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int id;
public String name;
public City(String name){
this.name = name;
}
}
But with this code, if I try to create an AdviceSheet, I got an
exception :
play.exceptions.JavaExecutionException: null id in models.AdviceSheet
entry (don't flush the Session after an exception occurs)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:228)
at Invocation.HTTP Request(Play!)
....
What's the problem ?
Is there any workaround ?
Thanks