HI, this is the first I would post on Hibernate forums although I have found many answers on them. Ok, here's my problem: I'm using Type Square pattern for which I've created 4 classes. These are: Product, ProductType, AttributeType and Attribute. The idea of all this is to be able to create products (with their corresponding attributes) at runtime. Otherwise, I'll need to create a table and a class per product. To sum up: - Product holds information about an instance of a product (id = "123") - ProductType holds information about its actual type (eg.: name = "Book") - AttributeType is the type of attribute (eg.: name = "author", clazz = "java.lang.String") - Attribute holds the value for a certain AttributeType and its related to a Product object (eg.: value = "John Doe")
With such information, here's my mapping: Many Products - One ProductType
One ProductType - Many AttributeType
One AttributeType - Many Attribute
Many Attribute - One Product
It obvious that "value" in Attribute class should be of type Object. However I do not know how to declare that at runtime it should be mapped to "clazz" in class AttributeType. Does it make sense at all?
Now, appart from that, for certain attributes, I need to restrict the allowed values. For instance, some attribute can be of type String, and its value can be "high", "medium" or "low", an that's it. Should I achieve that with Strategy pattern? Or is there any hibernated-way to do so?
|