Emmanuel,
Point well taken.... but the DB came before the current app and I don't have the power to change it!
I am close on the mapping I want to do, but not quite there. Here is what I have so far:
3 Java Classes
-------------------
UsersTO
- private long sequenceId;
- private String userName;
- private PreferencesTO preferences;
PreferencesTO
- private Map panelsettings;
- private String defaultViewName;
PanelSettingsTO
- private boolean minimized;
4 Tables
-------------------
u_users
- u_id NUMBER(6);
- user_name VARCHAR2(18);
u_preferences
- u_id NUMBER(6);
- default_view_name VARCHAR2(24);
u_panel_settings
- u_id NUMBER(6);
- panel_id NUMBER(4);
- minimized CHAR(1);
- primary key = u_id & panel_id
u_panels
- panel_id NUMBER(6);
- panel_name VARCHAR(17);
hbm.xml
---------------------------
Code:
<class name="UserTO" table="u_users"
<id name="sequenceId" column="u_id" type="long" unsaved-
value="0">
<generator class="sequence">
<param name="sequence">UID_SEQ</param>
</generator>
</id>
<property name="userName" column="user_name" type="string"/>
<one-to-one name="peferences" class="PeferencesTO" cascade="all"/>
</class>
<class name="PreferencesTO" table="u_preferences"
<id column="u_id" type="long" unsaved-value="0">
<generator class="foreign"></generator>
</id>
<property name="defaultViewName" column="default_view_name"
type="string"/>
<map name="panelSettings" table="u_panel_settings">
<key column="u_id">
<index column="panel_id" type="long"/>
<composite-element class="PanelSettingsTO">
<property name="minimized" type="yes_no"/>
</composite-element>
</map>
</class>
<class name="PanelSettingsTO" table="u_panel_settings"
<composite id name="panelSettings" class="PanelSettingsTO_PK">
<key-many-to_one name="panel" class="PanelTO">
<column name="panel_id"/>
</key-many-to-one>
<key-many-to_one name="user" class="UserTO">
<column name="u_id"/>
</key-many-to-one>
</composite id>
<property name="minimized" column="minimized" type="yes_no"/>
<many-to_one name="panelRef" class="PanelTO" column="panel_id"/>
</class>
<class name="PanelsTO" table="u_panels"
<id name="paneld" column="panel_id" type="long" unsaved-
value="0">
<generator class="sequence">
<param name="sequence">PANEL_ID_SEQ</param>
</generator>
</id>
<property name="panelName" column="panel_name" type="string"/>
</class>
The code/mappings above allow me to use the panel_id as a key into the the panelSettings Map. What I would like to do, actually what the app developer wants to do ;), is to use panel_name as the key. The problem is that panel_name is in another table (U_PANELS). In straight SQL, the answer is easy, just join U_PANEL_SETTINGS and U_PANELS on PANEL_ID, but I have not been able to do so with the hibernate mapping. I can get very close. I can either create the java.util.Map with panel_id as the key, or I can get hibernate to try and use panel_name but I get an error because it is trying to find the field in U_PANEL_SETTINGS. The question, is it possible to use a value from another table as the key into a <map>?
Thanks again,
Charles