Question

lets say i have a class named myClass1 and i have another class myClass2 such that myClass1 contains a collection of myClass2... storing this in java is very easy. i was wondering how can we do that if the values needs to be stored in a table in mysql?

i m trying to construct a table so that i can do something like this:

CREATE table myClass1(attr1 integer, attri2 char(), attri3 varchar(20), attri4 myClass2Collection)

any ideas how can i store attri4 that needs storing of a collection and that too of a user defined data type???

Was it helpful?

Solution

MyClass2 needs foreign keys to myClass1 (in MySQL)

You know about One-To-Many releationsships, dont you?

So MyClass1's structure can be copied into the table for MyClass1 WITHOUT the List/Collection. MyClass2's structure can be copied into the table for MyClass2 exdented by another Column including a foreign key fo the row in the MyClass1 table!

OTHER TIPS

Your main class should only contain references to its own data not its child collection.

But your child objects or data or table, should have an id to the parent.

Please understand primary and foreign key relationships.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top