#Saving an object that contains other object arrays.

31 messages · Page 1 of 1 (latest)

turbid cedar
#

Wondering how I could go about doing this, for simple data persistence. Doesn't have to have great performance.

The object I'm trying to save has the following:

Month[] months = new Month[12];

Inside each month, is

Day[] days;

and inside each day is

Meal[] meals = new Meals[99];
vital briarBOT
#

This post has been reserved for your question.

Hey @turbid cedar! Please use /close or the Close Post button 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.

sacred veldt
#

uhm, you just.. do just that?

#

not sure what the issue is

turbid cedar
#

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

sacred veldt
#

do you know how to write classes

turbid cedar
#

Yes?

sacred veldt
#

then you know how to solve this problem

#

start with the meal class

#

write a day class that has that

turbid cedar
#

Huh?

sacred veldt
#

write a month class that has that

turbid cedar
#

I'm wondering about data persistence

#

lol

sacred veldt
#

oh shit misread your question horribly lmao

#

that's what i get for skimming

turbid cedar
#

dw

#

happens

sacred veldt
#

sorry, don't know about db stuff in java

turbid cedar
#

npnp

dense loom
#

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

runic nest
turbid cedar
turbid cedar
runic nest
# turbid cedar I'd rather save it manually

if you want to do it really easy and really stupid:

  • create a table with a singe blob field
  • serialize the months object (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 months with fields that correspond to the fields of Month class (and id field to store identifier) and you store each of the month
  • create table days with fields that correspond to the fields of Day class (and id field to store identifier and month_id to store relation) and store
  • create table meals with fields that correspond to the fields of Meal class (and id field to store identifier and day_id to store relation to day)