Hibernate version: 3.0.6
Name and version of the database you are using: MySQL
I have a design best practices questions.
Let's say I have an class that has 3 java.util.Set which I want to map.
Code:
package domain.tool;
import java.util.Set;
public class Tools {
private Set<BusinessIntelligenceTool> businessIntelligence;
private Set<MonitoringTool> monitoringTools;
private Set<BuilderTool> buildTools;
}
All the 3 classes (BusinessIntelligenceTool, MonitoringTool and BuilderToon) extend the same parent class (AbstractTool), and therefore have the same fields (name). Typically, the one-to-many relationship that the collections create would require me to create 3 additonnal tables to store the relationships. I'd like to avoid that.
I'd like to know if it's possible to store all the entries in 1 table. This would for example be the mapping for one of the 3 classes in one of my Sets.
They'd all write to the table "TOOLS" which would be common for the all 3 classes...
Code:
<class name="domain.tool.BusinessIntelligenceTool" table="TOOLS">
<id name="id" column="ID" type="int">
<generator class="native"/>
</id>
<property name="name" type="string">
<column name="NAME" not-null="true" index="TOOL_NAME"/>
</property>
<property name="fk" type="int">
<column name="BI_TOOL_ID" />
</property>
<many-to-one name="project" class="domain.tool.Tools">
<column name="TOOLS_ID" not-null="true"/>
</many-to-one>
</class>
Is that a good design? Anything else to suggest?
Here are my questions.
- How can I map the 3 collections the better. Do I need to create 3 different tables, or is it possible to merge them into one...
- Wouldn't a kind of many-to-many be more appropriate?
Thanks a lot for your input!
Cheers,
Nicolas