-->
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: No row with the given identifier exists when outer-joining
PostPosted: Wed Jun 16, 2004 3:52 pm 
Newbie

Joined: Wed Jun 16, 2004 3:33 pm
Posts: 2
I am new to hibernate and I am studying many-to-one mapping and outer-join. I came up with following exception when I tried to retrieve a records:
Code:
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 3, of class: example.Team
        at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
        at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1918)
        at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
        at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215).........

The mapping is as follow:
Code:
  <class name="example.Player" table="players">
    <id name="id" column="player_id" type="long" unsaved-value="null">
      <generator class="hilo"/>
    </id>
    <property name="firstName" column="first_name" type="string" length="12" not-null="true"/>
   <property name="lastName" column="last_name" type="string" length="15" not-null="true"/>
   <property name="draftDate" column="draft_date" type="date"/>
   <property name="annualSalary" column="salary" type="float"/>
    <property name="jerseyNumber" column="jersey_number" type="integer" length="2" not-null="true"/>
   <many-to-one name="team" class="example.Team" column="team_id" outer-join="true"/>
  </class>
  <class name="example.Team" table="teams">
    <id name="id" column="team_id" type="long" unsaved-value="null">
      <generator class="hilo"/>
    </id>
    <property name="name" column="team_name" type="string" length="15" not-null="true"/>
    <property name="city" column="city" type="string" length="15" not-null="true"/>
    <set name="players" cascade="all" inverse="true" lazy="true">
      <key column="team_id"/>
      <one-to-many class="example.Player"/>
    </set>
  </class>

The code is as:
Code:
            Configuration cfg = new Configuration()
                .addClass(example.Player.class)
                .addClass(example.Team.class);
            SessionFactory factory = cfg.buildSessionFactory();   
            // open a session and save the team
            SessionFactory sessions = cfg.buildSessionFactory();
            Session session = sessions.openSession();
            // method 1: loading a persistent instance
            Iterator it = session.find("from Player").iterator();
            while(it.hasNext()) {
                Player player = (Player)it.next
                System.out.print(player.getId() + ": "+player.getFirstName());
                if(player.getTeam() != null)
                      System.out.print("\t" + player.getTeam().getId());
                System.out.println();
            }
            System.out.println("End:");

Here is the data:
Code:
PLAYER_ID FIRST_NAME LAST_NAME DRAFT_DATE SALARY   JERSEY_NUMBER TEAM_ID
--------- ---------- --------- ---------- -------- ------------- -------
300       Ed         Todd      (null)     12000.0 2             3       

I know that there is no team_id 3 in table Teams. With outer-join="true", I am expecting the player.getTeam() is null and the code still works.

Please help me understand where I am wrong and how to correct it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 4:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
HQL ignores mapping settings, use join fetch. Besides this is a really broken relational model which will soon cause you more trouble.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 5:50 pm 
Newbie

Joined: Wed Jun 16, 2004 3:33 pm
Posts: 2
Thank you so much for quick reply. I will try using join fetch. I am concerned about your comments about the broken relationship model. I am not sure wheather the trouble you are talking about will be from using hibernate or from database schema side. Could you please be more specific?


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.