[hibernate-users] Simple relationship problems

boliver at lvlomas.com boliver at lvlomas.com
Thu Apr 24 10:14:00 EDT 2008


I have a very simple DB structure that I can't seem to get going here with
Hibernate.

The relationship between two tables is quite simple.

Table:  Team - contains the following
pkid - int
name - varchar
divisionpkid - int

Table: Division - contains the following:
pkid - int
name - varchar

A team can belong to a division, and division can have many teams.  What I
want is to get all the teams from the database, and have a reference in
each team to it's division.

My hibernate hbm file looks like this:

<class name="database.HldivisionEntity" table="hldivision"
catalog="Twisters2008">
        <id name="pkid">
            <column name="pkid" sql-type="int" length="11" precision="0"
not-null="true"/>
        </id>
        <property name="name">
            <column name="name" sql-type="varchar" length="20"
precision="0" not-null="false"/>
        </property>
    </class>
    <class name="database.TeamEntity" table="team" catalog="Twisters2008">
        <id name="pkid">
            <column name="pkid" sql-type="int" length="11" precision="0"
not-null="true"/>
        </id>
        <property name="name">
            <column name="name" sql-type="varchar" length="20"
precision="0" not-null="false"/>
        </property>
        <property name="hldivisionpkid">
            <column name="hldivisionpkid" sql-type="int" length="11"
precision="0" not-null="false"/>
        </property>
        <one-to-one name="division" class="database.HldivisionEntity"/>
    </class>

In my code, when I execute this:

List teamList = session.createQuery("from TeamEntity" ).list();

I get a List returned of the two team records in my Team table, and the
hldivisionpkid fields are set correctly, the the division object is null.
So I must be doing something wrong here.  Have I missed something in my
configuration to make this relationship work correctly?

Thanks.

Bryan


----------------------------------------------------------------------------



CONFIDENTIALITY:  The information in this message is legally privileged and
confidential.  In the event of a transmission error and if you are not the
individual or entity mentioned above,  you are hereby advised that any use,
copying or reproduction of this document is strictly forbidden.  Please
advise us of this error and destroy this message.


CONFIDENTIALITÉ:  L'information apparaissant dans ce message électronique
est de nature légalement privilégiée et confidentielle.  Si ce message vous
est parvenu par erreur et que vous n'êtes pas le destinataire visé, vous
êtes par les présentes avisé que tout usage, copie ou distribution de ce
message est strictement interdit.  Vous êtes donc prié de nous informer
immédiatement de cette erreur et de détruire ce message.





More information about the hibernate-users mailing list