-->
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.  [ 2 posts ] 
Author Message
 Post subject: Trouble understanding <one-to-one> relation
PostPosted: Tue Mar 01, 2005 1:01 pm 
Newbie

Joined: Mon Feb 28, 2005 11:09 am
Posts: 7
Hi,

i´m in serious trouble understanding the one-to-one relationship in Hibernate. I´ve got two simple tables like this:
Code:
_____________           __________
|             |          |         |
| Einrichtung |          | Adresse |
|_____________|          |_________|
|             |          |         |
|     id      |    ----- |   id    |
|_____________|    |     |_________|
|             |    |     |         |
|    name     |    |     | street  |
|_____________|    |     |_________|
|             |    |     |         |
|   adressID  |<---      |   ...   |
|_____________|          |_________|

(Einrichtung is a german word, translate it with 'institution')
I´m trying hard to generate a mapping for this simple relation, without luck yet.

Hibernate version:2.7.1

Mapping documents:
Code:
<hibernate-mapping>
   <class name="myParentClass" table="ParentClass" dynamic-insert="true" dynamic-update="true" select-before-update="true" optimistic-lock="version">

      <id name="id" type="integer" unsaved-value="null">
         <column name="id" sql-type="integer" not-null="true"/>
         <generator class="identity"/>
      </id>
      <property name="name">
         <column name="name" length="255" not-null="false"/>
      </property>

      <one-to-one name="id" class="de.hannit.fsch.benutzerverwaltung.Adresse" cascade="none" />
   </class>
   <!-- Mapping für die Adresse -->   
   <class name="de.hannit.fsch.benutzerverwaltung.Adresse" table="Adresse" dynamic-insert="true" dynamic-update="true" select-before-update="true" optimistic-lock="version">
      <!-- Primärschlüssel für die Adresse -->
      <id name="id" type="integer" unsaved-value="null">
         <column name="id" sql-type="integer" not-null="true"/>
         <generator class="identity"/>
      </id>
      <property name="strasse">
         <column name="strasse" not-null="false"/>
      </property>
                 .
                 . other properties 
                 .
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
einrichtung = (Einrichtung) load(new Integer(iID));

(iID ==6)
Here is what Hibernate logs:
Code:
select einrichtun0_.id as id0_, einrichtun0_.name as name0_ from Einrichtung einrichtun0_ where einrichtun0_.id=?
Hibernate: select einrichtun0_.id as id0_, einrichtun0_.name as name0_ from Einrichtung einrichtun0_ where einrichtun0_.id=?
net.sf.hibernate.impl.BatcherImpl  - preparing statement
DEBUG net.sf.hibernate.type.IntegerType  - binding '6' to parameter: 1
DEBUG net.sf.hibernate.loader.Loader  - processing result set
DEBUG net.sf.hibernate.loader.Loader  - result row: 6
DEBUG net.sf.hibernate.loader.Loader  - Initializing object from ResultSet: 6
DEBUG net.sf.hibernate.loader.Loader  - Hydrating entity: de.hannit.fsch.benutzerverwaltung.Einrichtung#6
DEBUG net.sf.hibernate.type.StringType  - returning 'Pflegeheim Erdmöbel                                                                                                                                                                                                                                            ' as column: name0_
DEBUG net.sf.hibernate.loader.Loader  - done processing result set (1 rows)
DEBUG net.sf.hibernate.impl.BatcherImpl  - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG net.sf.hibernate.impl.BatcherImpl  - closing statement
DEBUG net.sf.hibernate.loader.Loader  - total objects hydrated: 1

so far, so good. But now, hibernate tries to load the adress object with using the same id ! (6)
Code:
DEBUG net.sf.hibernate.impl.SessionImpl  - resolving associations for [de.hannit.fsch.benutzerverwaltung.Einrichtung#6]
DEBUG net.sf.hibernate.impl.SessionImpl  - loading [de.hannit.fsch.benutzerverwaltung.Adresse#6]
DEBUG net.sf.hibernate.impl.SessionImpl  - attempting to resolve [de.hannit.fsch.benutzerverwaltung.Adresse#6]
DEBUG net.sf.hibernate.impl.SessionImpl  - object not resolved in any cache [de.hannit.fsch.benutzerverwaltung.Adresse#6]
DEBUG net.sf.hibernate.persister.EntityPersister  - Materializing entity: [de.hannit.fsch.benutzerverwaltung.Adresse#6]
DEBUG net.sf.hibernate.impl.BatcherImpl  - about to open: 0 open PreparedStatements, 0 open ResultSets
DEBUG net.sf.hibernate.SQL  - select adresse0_.id as id0_, adresse0_.strasse as strasse0_, adresse0_.hausnummer as hausnummer0_, adresse0_.zusatz as zusatz0_, adresse0_.postleitzahl as postleit5_0_, adresse0_.ort as ort0_ from Adresse adresse0_ where adresse0_.id=?
Hibernate: select adresse0_.id as id0_, adresse0_.strasse as strasse0_, adresse0_.hausnummer as hausnummer0_, adresse0_.zusatz as zusatz0_, adresse0_.postleitzahl as postleit5_0_, adresse0_.ort as ort0_ from Adresse adresse0_ where adresse0_.id=?
DEBUG net.sf.hibernate.impl.BatcherImpl  - preparing statement
DEBUG net.sf.hibernate.type.IntegerType  - binding '6' to parameter: 1
DEBUG net.sf.hibernate.loader.Loader  - processing result set
DEBUG net.sf.hibernate.loader.Loader  - done processing result set (0 rows)
DEBUG net.sf.hibernate.impl.BatcherImpl  - done closing: 0 open PreparedStatements, 0 open ResultSets
DEBUG net.sf.hibernate.impl.BatcherImpl  - closing statement
DEBUG net.sf.hibernate.loader.Loader  - total objects hydrated: 0


I am totally confused. Any suggestions for me ?

Name and version of the database you are using:MS SQL Server 2000

The generated SQL (show_sql=true):see log


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If the one-to-one is not using a shared primary key, you have to use a property-ref mapping


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.