Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate configuration, then a simple join

 
Pascal Steiner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi together

I defined in the table module the follow relationship:

<set name="kompetenzen" table="REL_MODULE_KOMP" lazy="true">
<key column="MOD_ID"/>
<many-to-many column="KPT_ID" class="ch.abbts.wemo.entity.Kompetenz"/>
</set>

My first question is, if i have to do the same in the table kompetenz or is that enough if i specify the relationship only in my table module?

with this configuration, i was able to save information with hibernate, which has create automatically the table REL_MODULE_KOMP by going this way:

Kompetenz k = new Kompetenz();
Modul m = new Modul();
m.getKompetenzen().add(k);

Now my second question: i try to realise a join with the both tables. With SQL:

SELECT * FROM module
inner join `rel_module_komp`
using(`MOD_ID`)
WHERE
`KPT_ID` = ???

how can i realize this in hibernate? i tryed out many ways, but not the correct one :-(

from Modul m inner join Kompetenz where Kompetenz.id=:kid
-> Path expected for join!

from Modul m inner join rel_module_komp on rel_module_komp.MOD_ID = modul.id where rel_module_komp.KPT_ID=:kid
-> unexpected token: ON

from Modul m inner join Kompetenz.MOD_ID where Kompetenz.KPT_ID=:kid
-> Invalid path: 'Kompetenz.MOD_ID'

from Modul m inner join rel_module_komp.MOD_ID where rel_module_komp.KPT_ID=:kid
-> Invalid path: 'rel_module_komp.MOD_ID'

from Modul m inner join m.rel_module_komp.MOD_ID where m.rel_module_komp.KPT_ID=:kid
-> could not resolve property: rel_module_komp

from Modul m inner join m.Kompetenz.MOD_ID where m.Kompetenz.KPT_ID=:kid
-> could not resolve property: Kompetenz

....

Hope, someone can show me a working solution...


Thx for the "beginner help"

Greetings

Pascal

PS: Here my comlete mapping for the two tables:

<class name="ch.abbts.wemo.entity.Modul" table="MODULE">
<id name="id">
<column name="MOD_ID" length="10" not-null="true"/>
<generator class="native"/>
</id>
<many-to-one name="firma"
class="ch.abbts.wemo.entity.Firma"
column="R_SOCI"
insert="true"
update="true"
not-null="true"/>
<property name="titel">
<column name="MOD_TITEL" length="120" not-null="true"/>
</property>
<property name="dauer">
<column name="MOD_DAUER" length="3"/>
</property>
<property name="typ">
<column name="MOD_TYP" length="2"/>
</property>
<many-to-one name="phase"
class="ch.abbts.wemo.entity.Phase"
column="PHA_ID"
insert="true"
update="true"
not-null="false"/>
<many-to-one name="schwerpunkt"
class="ch.abbts.wemo.entity.Schwerpunkt"
column="SWP_ID"
insert="true"
update="true"
not-null="false"/>
<many-to-one name="lehrgang"
class="ch.abbts.wemo.entity.Lehrgang"
column="LHG_ID"
insert="true"
update="true"
not-null="true"/>
<many-to-one name="evaluation"
class="ch.abbts.wemo.entity.Evaluation"
column="EVA_ID"
insert="true"
update="true"
not-null="false"/>
<set name="literatures" table="REL_MODULE_LITERATUR" lazy="true">
<key column="MOD_ID"/>
<many-to-many column="LIT_ID" class="ch.abbts.wemo.entity.Literatur"/>
</set>
<set name="sqs" table="REL_MODULE_SQ" lazy="true">
<key column="MOD_ID"/>
<many-to-many column="SQ_ID" class="ch.abbts.wemo.entity.SQ"/>
</set>
<set name="funktionen" table="REL_MODULE_FUNKTIONEN" lazy="true">
<key column="MOD_ID"/>
<many-to-many column="LFK_ID" class="ch.abbts.wemo.entity.Funktion"/>
</set>
<set name="kompetenzen" table="REL_MODULE_KOMP" lazy="true">
<key column="MOD_ID"/>
<many-to-many column="KPT_ID" class="ch.abbts.wemo.entity.Kompetenz"/>
</set>
<list name="situationen" table="SITUATION" lazy="true">
<key column="MOD_ID"/>
<index column="SMZ_POSITION"/>
<one-to-many class="ch.abbts.wemo.entity.Situation"/>
</list>
<property name="modifiedBy">
<column name="R_USER" length="8" not-null="true"/>
</property>
<property name="lastModification" type="timestamp">
<column name="R_DATE" not-null="true"/>
</property>
<property name="modifiedWith">
<column name="R_PROG" length="8" not-null="true"/>
</property>
</class>

<class name="ch.abbts.wemo.entity.Kompetenz" table="KOMPETENZ">
<id name="id">
<column name="KPT_ID" length="10" not-null="true"/>
<generator class="native"/>
</id>
<many-to-one name="firma"
class="ch.abbts.wemo.entity.Firma"
column="R_SOCI"
insert="true"
update="true"
not-null="true"/>
<property name="titel">
<column name="KPT_TITEL" length="120" not-null="true"/>
</property>
<many-to-one name="lehrgang"
class="ch.abbts.wemo.entity.Lehrgang"
column="LHG_ID"
insert="true"
update="true"
not-null="true"/>
<set name="resourcenWissen" table="REL_KOMPETENZ_RESWISSEN" lazy="true">
<key column="KPT_ID"/>
<many-to-many column="RSW_ID" class="ch.abbts.wemo.entity.ResourceWissen"/>
</set>
<set name="resourcenKoennen" table="REL_KOMPETENZ_RESKOENNEN" lazy="true">
<key column="KPT_ID"/>
<many-to-many column="RKO_ID" class="ch.abbts.wemo.entity.ResourceKoennen"/>
</set>
<property name="modifiedBy">
<column name="R_USER" length="8" not-null="true"/>
</property>
<property name="lastModification" type="timestamp">
<column name="R_DATE" not-null="true"/>
</property>
<property name="modifiedWith">
<column name="R_PROG" length="8" not-null="true"/>
</property>
</class>
 
Pascal Steiner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it. My solution:

from Modul as mod where mod.kompetenzen.id=:kid

Greetings & hope, this can help someone else

Pascal
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic