I am working with web-based online exam application and now I have little problem with hibernate mappings.
Hibernate version: 3.0.5
Name and version of the database you are using: MySQL 4.1.14
I have table called
section that holds following kind of information:
Code:
SEid integer PK
SEtyid char(1)
SEdate timestamp
SEtxt text
SEweight integer
SEguide1 text
SEguide2 text
SElang char(1)
Important fields in this problem are:
SETYid The type of the section (A,B,C,D or E)
SEguide1 Help text to be shown in user interface
SEguide2 Another help text
SElang language code
At the moment there are 16 different tests in the system so there are also 16 sections with type A, 16 with type B and so on. Because help texts in sections with certain type are quite similar, I have made table called
parameter that holds default help texts to sections.
Code:
PAname varchar(10) PK
PAlang char(1) PK
PAsetyid char(1) PK
PAtxt text
The idea is that if SEguide1 and/or SEguide2 is null then application will show defalut text from parameter table. Connection between tables is SElang=PAlang and PAsetyid=SEtyid
Mapping documents:Parameter.hbm.xmlCode:
<class name="Parameter" lazy="false" table="parameter" discriminator-value="foo.bar.Parameter" optimistic-lock="none">
<composite-id name="id" class="foo.bar.Parameter$Id" unsaved-value="undefined">
<key-property name="palang" type="character">
<column name="PAlang" not-null="true" index="PRIMARY" length="1"/>
</key-property>
<key-property name="paname" type="string">
<column name="PAname" not-null="true" index="PRIMARY" length="10"/>
</key-property>
<key-property name="pasetyid" type="character">
<column name="PAsetyid" not-null="true" index="PRIMARY" length="1"/>
</key-property>
</composite-id>
<property name="patxt" type="string">
<column name="PAtxt"/>
</property>
</class>
</hibernate-mapping>
My question is that how do I map <bag> of parameters in the section.hbm.xml when I don't want to use section-table's primary key? I tried <key property-ref=""> but then I only could use one column. I need to use two columns (SElang=PAlang and PAsetyid=SEtyid)! This would be easy to solve with plain SQL but i don't know how to do this with hibernate.
I hope you can understand my confusing post!
Any help would be greatly appreciated.