Home > Blockchain >  Store java object which contains another object on a single table with JPA
Store java object which contains another object on a single table with JPA

Time:11-07

I'm doing an exercise with Springboot that basically consists of a simple application with a Rest Controller who has to store an object received from POST request to a mysql db using JPA/Hibernate. My problem is the following one:

the table has this structure:

enter image description here

And I have this pojo which has to map the table as an object:

enter image description here

If you pay attention, the table has a column named "CARD_HOLDER_FULL_NAME", but in the app, the card holder must be a separate object:

enter image description here

so, how do I specify that the fullName attribuite in the CaldHolderInfo class represents that column in the table?

I'm very rusty with Springboot/JPA/hibernate so I don't know how to proceed

CodePudding user response:

You need to make CaldHolderInfo an Embeddable.

See JPA @Embedded And @Embeddable

And please, no images of code on this site.

  • Related