• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Model design confusion...

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, using hibernate 3.1 in a swing based app and confused on the best approach to take.

I have 2 objects, contacttypes and contacts, contact types just denote the type of person, e.g. friend, employer, and the contact object/table contains name address etc.. i have a swing frame with two jtables listing the contact types which when a row is selected the second table is populated with a list of all contacts of the selected type. and when a contact is selected i present the details using textfields/labels etc..

What I want to build into my app is the ability for users to create 'custom fields'. so a particular contact type will have a set of defined custom fields applicable to it. and when a contact is selected , i want to present in another table, the allowable custom fields for its type and their values if they've been set.

Coming up with the model for this is quite tricky, I have the classes i want to use and know how i'd like to use them, but linking them together for hibernate and using them via a TableModel is bloody confusing. Ideally when i create a tablemodel for the custom fields JTable, I think i should be somehow showing populated custom fields and also creating custom field objects for the defined fields which yet have not been populated :\....

Any help appreciated.

Thanks...
 
Sebastian Hennebrueder
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello James,
some ideas:
have a look in the Hibernate Reference (not in my book ;-) ) and read about Dynamic Mapping for example using a Map.

Fields are created once and will not be changed frequently.
Create a table with a column for each custom field. table contact_customer_fields (custField1, custField2, ...) Mapping can easily be done with dynamic mapping.
Main advantage: fast! as there is only a join of one row to the standard row.

Fields could be changed often:
Create a table defining the column
custom_columns(id, type)
custom_columns_values (master_row_id, custom_columns_id, type)
Man advantage: flexible
Disadvantage: large joins or even impossible to join
use with jtable could be tricky.
Best Regards Sebastian
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sebastian.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic