Search code examples
javamysqltypescollectionsuser-defined

user defined data type in mysql with java


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???


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!