-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem with 1:n mapping
PostPosted: Wed Sep 14, 2005 7:06 am 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
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

Help !!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 14, 2005 7:17 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
Hi,

The solution is, I think, to use property-ref. But as far as I can remember, it must be used on the many-to-one side.

Could you post both mappings - if you can't figure out how property-ref would work in your case?

Erik


Top
 Profile  
 
 Post subject: Mappingfiles for that problem for Erik
PostPosted: Wed Sep 14, 2005 7:39 am 
Newbie

Joined: Wed Aug 24, 2005 9:02 am
Posts: 15
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.