Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a decent default toString() implementation for entity beans (that don't have an implementation) #2641

Closed
rbygrave opened this issue Apr 8, 2022 · 0 comments · Fixed by #2642
Assignees
Milestone

Comments

@rbygrave
Copy link
Member

rbygrave commented Apr 8, 2022

For entity beans that do not already have a toString() implementation ... Ebean enhancement can provide a good default implementation.

The implementation needs to take into account recursion (e.g. bidirectional parent child relationships) and not invoke any interception or lazy loading.

Lazy loading / no interception

This isn't really a thing/issue. Ebean enhancement already ensures that there is no interception with any toString() implementation. Just stating it for completeness and to be explicit.

Recursion

This is a thing that we hit most of the time with entity beans so important and good that this deals with it. A lot of entities have the classic bidirectional parent -> OneToMany -> children ... with those children having the ... child -> ManyToOne -> parent. So a naive toString implementation would often result in an infinite loop (just like for example JSON serialisation). So it's good that this implementation deals with this.

Examples:

Customer@0(id:1, status:GOOD, inactive:false, name:usingConnection, version:1, whenCreated:2022-04-11 13:47:07.198, whenUpdated:2022-04-11 13:47:07.198)

Note that the @0 is the bean 'index' value of zero. When we get recursion, the content isn't repeated but instead includes something like Customer@0 that points back to the bean [that has already been output].

@rbygrave rbygrave self-assigned this Apr 8, 2022
@rbygrave rbygrave added this to the 13.2.1 milestone Apr 8, 2022
rbygrave added a commit that referenced this issue Apr 8, 2022
rbygrave added a commit that referenced this issue Apr 11, 2022
#2641 -  Provide a decent default toString() implementation for entity beans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant