Hi,
Play-ebean module behind the scene uses Ebean 7.x.
What I find is that, given issue happens when we try to serialize User model with jackson which has OneToMany relationship with Set<UserEmail>, and the way jackson accesses the model using reflection it causes bean to trigger another query to fetch UserEmail again, in place of using eager loaded object.
javax.persistence.EntityNotFoundException: Lazy loading failed on type:models.UserMobile id:7045548398 - Bean has been deleted.
at com.avaje.ebean.bean.EntityBeanIntercept.loadBeanInternal(EntityBeanIntercept.java:760)
at com.avaje.ebean.bean.EntityBeanIntercept.loadBean(EntityBeanIntercept.java:729)
at com.avaje.ebean.bean.EntityBeanIntercept.preGetter(EntityBeanIntercept.java:816)
at models.UserMobile._ebean_get_isVerified(UserMobile.java:6)
at models.UserMobile.getIsVerified(UserMobile.java:54)
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:633)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:678) If we comment jackson serialization and call simple getUserEmail method, then extra query to userEmail is not fired. So somewhere jackson is doing something.
So in short while serializing User with jackson, it fires a new query :
select t0.email_id c0, t0.usr_id c5 from user_email t0 where t0.email_id = ? ; --bind(sas...@gmail.com)
Above query is not fired if we do a simple get method call for user.userEmail, but it fires above query while serializing with jackson
Models (UserEmail and UserMobile in logs class are synonymous.)
@Getter@Setter
class User{
@Id
@Column(name = "usr_id", insertable = false, updatable = false)
private String id;
@Column(name = "usr_nick")
private String nickname;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user", cascade = CascadeType.ALL)
private Set<UserEmail> userEmail;
}
@Getter@Setter
class UserEmail {
@Id
private String emailId;
@JsonIgnore @ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name = "usr_id") private User user;
}
//json ignore annotation above belongs to jackson.