Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA recursive entity

 
Howard Watson
Ranch Hand
Posts: 64
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a User entity generated in Netbeans from an existing database table. The table has a column lastUpdatedByUser that is a User entity. Most of the tables in this database have a lastUpdatedByUser column and queries against those entities correctly return a user object as part of the result.

Ex. Retrieve FROM ProductionTable WHERE date = 'someDate' has a lastUpdatedByUser object that shows who last updated the table row and the rest of their user attributes.

If the productionTable data is edited in the web-app and submitted I need to update the lastUpdatedByUser column.

returns a User object that contains a lastUpdatedByUser that is a User object that contains a lastUpdatedByUser that is a User object that contains a lastUpdatedByUser object.... (I have no clue how many there are, and twenty rows of these adds up)

After I persist this

I get Json StackOverflowError in the next request for the updated entity

The Users entity definition:

How can I edit that such that I continue to get a user object as part of other entities like Production, but only a single lastUpdatedByUser object for a User entity?

Thanks for any insight.
 
Howard Watson
Ranch Hand
Posts: 64
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing this is my issue:

as I found a FK in the Users table to its own UserId

Love refactoring
 
Howard Watson
Ranch Hand
Posts: 64
1
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Drop that FK from the Users table and regenerate the entity in Netbeans and I get

like it should be
instead of

Wish I'd caught that (understood) on day one. That was the first table I generated and coded against in this refactor. Now I get to edit all the entities that have valid FKs into the Users table and code and...

Thanks for listening.

Have a great weekend.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howard Watson wrote:Wish I'd caught that (understood) on day one. That was the first table I generated and coded against in this refactor. Now I get to edit all the entities that have valid FKs into the Users table and code and...

Glad to hear you have found the solution for your problem yourself!

Thanks for coming back and sharing your solution! That might be very helpful for other ranchers. Have a cow!

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic