Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to store a java object with variable number of attributes
    primarykey
    data
    text
    <p>I've looked at <a href="https://stackoverflow.com/questions/1444462/how-to-store-data-with-dynamic-number-of-attributes-in-a-database">How to store data with dynamic number of attributes in a database</a>, but it didn't quite answer my question. The system I am implementing is rather large, so I'll stick with the objects I am concerned about: Item and Category. An Item has a variable number of attributes depending on the Category that it belongs to. For instance, Items belonging to the "T-shirt" Category would have an attribute for size, while Items belonging to the "Car" Category would have an attribute for model. Someone logged into the system as an Admin can create new Categories with completely new attributes. What's the best way to structure this both in my Java code and in my database to make this work? </p> <p>If the categories weren't dynamically created, I'd use inheritance so that I would have a TShirtItem object with its specific attributes filled in. But since it is dynamic, I'm puzzled. I saw a similar question that suggested using the Map data structure, but I am not sure how that would work...</p> <p>The question I referred to at the top would suggest on the database end that I would have an Category table, and Attributes table, and relationship table linking what attributes go with what Category. This makes sense. But I'm tripped up again when thinking about the Item object. I could store the unique Category_ID in the Item table, but where would I store the attributes for each Item? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload