Attempting, using Spring Boot with JPA, to read data from an API, and then save that data into my DB with some alterations.
I have an Entity like:
@Entity
@Table(name="BOOK_TABLE")
public class Book{
//...some normal variables (name, pageCount, etc.)
//I don't want this in the table
@Transient SeriesSummary seriesSummary;
//I want to save the output of this to the table
public Integer getSeriesId() {
//... does some stuff that figures out the id from the SeriesSummary
return seriesId;
}
}
So that I could map a book to the BOOK_TABLE:
book_id, name, pageCount..., seriesId
This seriesId could be used to look up a Series object in a SERIES_TABLE. But the Series object is different than the SeriesSummary object from my Book class. The SeriesSummary is just something coming from the API that provides the URL to look up the Series from the foreign API and its Id. I have no interest in storing this URL. I just want to grab the Book object, and then I will look up the Series object, store both, and map them together in my DB.
I can't seem to get Spring + JPA to save the output of the getSeriesId function. Can you only save class variables? If so how would you work around this?
The format of these objects is structured in the same way as the foreign API so that I can download the data objects using RestTemplate. Do I need to create a separate Class just for saving the columns I want?
Thank you!