#Saving an object that contains other object arrays.
31 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @turbid cedar! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Never done it before ahahahahah
Just need some guidance
Can't find what I'm looking for online, kinda late so my mind isn't working well
do you know how to write classes
Yes?
then you know how to solve this problem
start with the meal class
write a day class that has that
Huh?
write a month class that has that
sorry, don't know about db stuff in java
npnp
you could just like
dump it to json or something
basically find a way to searlize it
and then store the string in the db
do you want to use ORM tool, or save the data manually?
I'd rather save it manually
How would I serialize an array of objects that contain an array of objects in a way that i could load it back in? I'm stuck on that 🤣
if you want to do it really easy and really stupid:
- create a table with a singe blob field
- serialize the
monthsobject (make sure that Month, Day, Meal classes implement Serializable interface) into a byte array - put that data into table
if you want to do it right, you will need: - create table
monthswith fields that correspond to the fields of Month class (andidfield to store identifier) and you store each of the month - create table
dayswith fields that correspond to the fields of Day class (andidfield to store identifier and month_id to store relation) and store - create table
mealswith fields that correspond to the fields of Meal class (andidfield to store identifier and day_id to store relation to day)