EntityNotFoundException: Lazy loading failed frequent intermittent issue with play-ebean-3.0.1

622 views
Skip to first unread message

Shobhit Singh

unread,
Mar 29, 2017, 4:47:18 AM3/29/17
to eb...@googlegroups.com
Hi All,
 We are facing quite frequent issue on production where we are getting EntityNotFoundException exception when trying to do any operation on eager initialized manyToOne or oneToMany related objects.

We are using play 2.5 with > "com.typesafe.sbt" % "sbt-play-ebean" % "3.0.1"

javax.persistence.EntityNotFoundException: Lazy loading failed on type:models.User id:138568956 - 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.User._ebean_get_email(User.java:6)


Is this a bug in existing bean? I read it somewhere that its related to weak reference used in ebean, but its very old thread. Is this issue still existing with above mentioned version. Any pointers how to debug this.

Thanks,
Shobhit

Daryl Stultz

unread,
Mar 29, 2017, 7:00:13 AM3/29/17
to eb...@googlegroups.com
On Wed, Mar 29, 2017 at 4:47 AM, Shobhit Singh <shobhi...@quikr.com> wrote:
Hi All,
 We are facing quite frequent issue on production where we are getting EntityNotFoundException exception when trying to do any operation on eager initialized manyToOne or oneToMany related objects.

We are using play 2.5 with > "com.typesafe.sbt" % "sbt-play-ebean" % "3.0.1"

I'm not sure, does this mean you are using Ebean 3.0.1?

What does your User look like? Can you enable logging for SQL and post the query that's doing the loading?

/Daryl

Shobhit Singh

unread,
Mar 29, 2017, 8:34:58 AM3/29/17
to eb...@googlegroups.com
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.

--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shobhit Singh

unread,
Mar 29, 2017, 8:58:03 AM3/29/17
to eb...@googlegroups.com
Its not related to jackson, we are finding normal getters/setters to fail too.

In below case we fetched User from UserEmail object other way round and try to set one field inside that user object:

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.User._ebean_get_email(User.java:6) at models.User._ebean_set_email(User.java:1) at models.User.setEmail(User.java:324)


Thanks,
Shobhit

Daryl Stultz

unread,
Mar 29, 2017, 9:31:17 AM3/29/17
to eb...@googlegroups.com
On Wed, Mar 29, 2017 at 8:58 AM, Shobhit Singh <shobhi...@quikr.com> wrote:
Its not related to jackson, we are finding normal getters/setters to fail too.

Is @Getter@Setter a Play thing? Lombok? There aren't a lot of Play experts here. Can you try writing normal getters and setters and see how it goes?

/Daryl

Shobhit Singh

unread,
Mar 31, 2017, 2:05:22 AM3/31/17
to eb...@googlegroups.com
Thanks Daryl,
We were able to solve this, issue was happening because ebean was just fetching only the id column of manyToOne related objects, and not all attributes. Using fetch method we were able to resolve this.  

Regards,
Shobhit

--
Reply all
Reply to author
Forward
0 new messages