hi there, i have a tiny problem with correct 1:n mappings in hibernate. E.g. I have two tables, one table containing languagedescriptors in certain languages for "*_mldID" keys, which are stored in tables containing data which has to be shown in certain languages within the application.
e.g.
TABLE roles containing the following fields
roleID
roleName_mldID (Name of Role: is a unique ID for a set of language descriptors for roleName in the languagedescriptors Table)
roleFunction_mldID (Function of Role: is a unique ID for a set of language descriptors for roleFunction in the languagedescriptors Table)
TABLE languagedescriptors containing the following fields
languageDescriptorID (that's what the _mldID's point to)
languageID (the language of the languagedescriptor)
languageDescriptorValue (the value of the languagedescriptor)
e.g.
roleName_mldID = 2
|
|
2 | 1 Benutzer (german language, languageID=1)
2 | 2 User (englisch language, languageID=2)
roleFunction_mldID = 3
|
|
2 | 1 ein Internet-Benutzer(german language, languageID=1)
2 | 2 an internet user (englisch language, languageID=2)
the languageDescriptorID is referenced by the _mldID fields in the roles Table. I dont know how to get hibernate to understand that (in this case) there are two different 1:n mappings coming from the roles table referencing sets of descriptors in the languagedescriptors table.
the part of Roles.hbm.xml i'm currently using which dont work :( is:
<set
name="roleName_mlds"
lazy="true"
table="LanguageDescriptors">
<key column="languageDescriptorID"/>
<one-to-many class="net.someproject.LanguageDescriptorData"/>
</set>
i dont know where to tell hibernate that it has to use the roleName_mldID as key for its mapping and not the PK of the table Roles
the mappingfiles are shown below:
Roles.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="net.someproject.RoleData"
table="Roles">
<id name="roleID"
type="long">
<generator class="native"/>
</id>
<!--
mehrsprachige Bezeichner (Name des Rolle) (1:n)
here the roleName_mldID's missing !!! dont know where to put it (is that the property-ref?=)
-->
<set
name="roleName_mlds"
lazy="true"
table="LanguageDescriptors">
<key column="languageDescriptorID"/>
<one-to-many class="net.someproject.LanguageDescriptorData"/>
</set>
<!--
mehrsprachige Bezeichner (Funktion der Rolle) (1:n)
here the roleFunction_mldID's missing !!! dont know where to put it (is that the property-ref?=)
-->
<set
name="roleFunction_mlds"
lazy="true"
table="LanguageDescriptors">
<key column="languageDescriptorID"/>
<one-to-many class="net.someproject.LanguageDescriptorData"/>
</set>
</class>
</hibernate-mapping>
LanguageDescriptors.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="net.someproject.LanguageDescriptorData"
table="LanguageDescriptors">
<id name="languageDescriptorID"
type="long">
<generator class="native"/>
</id>
<property name="languageDescriptorValue" type="string"/>
<!--
Beziehung LanguageDescriptorData / LanguageData (n:1)
-->
<many-to-one
name="languageData"
column="languageID"
class="net.someproject.LanguageData"
/>
</class>
</hibernate-mapping>
Languages.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="net.someproject.LanguageData"
table="Languages">
<id name="languageID"
type="long">
<generator class="native"/>
</id>
<property name="languageShortcut" type="string"/>
</class>
</hibernate-mapping>
Erik's suggestion with property-ref did not work (or i used em wrong!)
Help!!!
Help !!!
|