-->
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.  [ 1 post ] 
Author Message
 Post subject: Getting values of Bidrectional Association
PostPosted: Fri Jan 25, 2008 9:39 am 
Newbie

Joined: Fri Jan 25, 2008 9:07 am
Posts: 5
Hello all,

i'm quite a newbe on hibernate an have a problem on bidrectional associations.

I have three DB - Tables with following association.

Visite(1) <--> (m)Visite2Probe(m) <--> (1)Probe

Assume i want following information of these three tables/objects.
Here the common SQL stmt of what i want as result:

Code:
Select proben.kurztext as probenname, visiten.kurztext as visitename
from proben
inner join visiten2proben on proben.internalid = visiten2proben.fkProbenID
inner join visiten on visiten.internalid = visiten2proben.fkVisitenID
where visiten.internalid = 1



Ok - here is what i already have.
Mappings:

Mapping of table Proben
Code:
<hibernate-mapping>
<class name="dBStudien2Obj.Proben" table="proben" catalog="studien">
        <id name="internalid" type="java.lang.Integer">
            <column name="internalid" />
            <generator class="identity" />
        </id>
        <property name="kurztext" type="string">
            <column name="kurztext" length="10" />
        </property>

        <set name="visiten2probens" inverse="true">
            <key>
                <column name="fkProbenID" />
            </key>
            <one-to-many class="dBStudien2Obj.Visiten2proben" />
        </set>
</class>
</hibernate-mapping>


Mapping of Table Visiten
Code:
<hibernate-mapping>
<class name="dBStudien2Obj.Visiten" table="visiten" catalog="studien">
        <id name="internalid" type="java.lang.Integer">
            <column name="internalid" />
            <generator class="increment" />
        </id>
           <property name="kurztext" type="string">
          <column name="kurztext" length="10" />
        </property>
<set name="visiten2probens" inverse="true">
            <key>
                <column name="fkVisitenID" />
            </key>
            <one-to-many class="dBStudien2Obj.Visiten2proben" />
        </set>
</class>
</hibernate-mapping>


Finally the join - table visiten2proben
Code:
<hibernate-mapping>
    <class name="dBStudien2Obj.Visiten2proben" table="visiten2proben" catalog="studien">
        <id name="internalid" type="int">
            <column name="internalid" />
            <generator class="assigned" />
        </id>
        <many-to-one name="proben" class="dBStudien2Obj.Proben" fetch="select">
            <column name="fkProbenID" />
        </many-to-one>
        <many-to-one name="visiten" class="dBStudien2Obj.Visiten" fetch="select">
            <column name="fkVisitenID" />
        </many-to-one>
    </class>
</hibernate-mapping>


Further more i already have the classes to the table generated with hibernate tools.
And then i created a class StudienManager in which i try to provide methods for getting access to my data.

One method in class StudienManager would be.
Code:
public ??? getProbesANDVisitnameToVisite(pkVisiteID)
{
   Session session = HibernateSessionFactory.currentSession();
   session.beginTransaction();
//What do i have to code here to get the right data like the above sql - stmt
//?????????????

session.commit();
}


So far.
I have some questions.
1. Is the mapping of the tables ok - correct and well designed.
2. And what is the best way to get the right result corresponding the sql - stmt at the top of this post. --> How has the Method getProbesANDVisitnameToVisite(...) to look like???
And what kind of Object should i return on that method? (Probe or Visite)

What is the best way to go for that?

Unfortunately i found no tutorials which would do the select.

I hope you can help me...

Regards


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

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.