-->
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.  [ 5 posts ] 
Author Message
 Post subject: UnresolveableObject Exception w/ left outer join and a join
PostPosted: Thu May 12, 2005 6:09 pm 
Newbie

Joined: Thu May 12, 2005 5:41 pm
Posts: 3
This is my first post in this forum and I think I have read the instructions & other docs, so please bear with me.

To summarise, A is my main table; am trying to do a join with B and a left outer join with C.

When there is no corresponding record in C for a record in A, I am getting an UnresolvableObjectException.

Also, I noticed that this process involves two queries. First query does the outer join and then the second query executes the join.

Are two queries expected in this scenario and how can I resolve the exception problem?


Hibernate version:2.1.7

Mapping documents:

<hibernate-mapping package="com.xyz" >

<class name="A" table="A" mutable="false">
<id name="a1" column="A1" type="java.lang.Long">
<generator class="assigned"/>
</id>

<many-to-one class="B" name="b" column="A2" not-null="false" outer-join="false" insert="false"/>

<property name="a3" column="A3" type="string" />
<property name="a4" column="A4" type="string" />

<many-to-one class="C" name="c" not-null="false" outer-join="true" insert="false" update="false">
<column name="A3"/>
<column name="A4" />
</many-to-one>
</class>

<class name="B" table="b">
<id name="id" column="A2" type="java.lang.Long">
<generator class="assigned"/>
</id>

<property name="b1" column="B1" type="string"/>
</class>

<class name="C" table="c">
<composite-id class="CKey">
<key-property name="a3" column="A3" type="string"/>
<key-property name = "a4" column="A4" type="string"/>
</composite-id>

<property name="c1" column="C1" type="string"/>
</class>




Code between sessionFactory.openSession() and session.close():

String sql = "from A as a left join fetch a.c where a.a1 = :a1";
query = session.createQuery(sql);
query.setParameter("a1", 1234);
list = query.list();


Full stack trace of any exception that occurs:

net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: com.xyz.CKey@13c765e[hashValue=1960441316,a3=14,a4=BKABC]

Name and version of the database you are using:
oracle 9.2.0

The generated SQL (show_sql=true):
select .... from A a0_ left outer join C c1_ on a0_.A3=c1_.A3and a0_.A4=c1_.A4 where (a0_.A=? )


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 2:12 pm 
Newbie

Joined: Thu May 12, 2005 5:41 pm
Posts: 3
Do I need to provide more info? Or have I fumbled on to a question that has no answer ;) Please let me know.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 3:05 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
srhmlpt wrote:
Do I need to provide more info? Or have I fumbled on to a question that has no answer ;) Please let me know.


I just built a test case around your mapping file and it worked fine for me. (Although I'm using 2.1.8 and hsqldb 1.7.2.)

Code:
public class UnresolvableObjectExceptionTest {

   private static final Logger logger = Logger.getLogger(UnresolvableObjectExceptionTest.class);

   static SessionFactory sessionFactory;

   public static void main(String[] args) throws Exception {
      UnresolvableObjectExceptionTest tester = new UnresolvableObjectExceptionTest();
      tester.setUp();
      tester.testUnresolvableObjectExceptionTest();
   }
   
   private void setUp() throws Exception {
      Session session = getSession();
      Transaction tx = session.beginTransaction();
      
      B b1 = new B();
      b1.setId(new Long(1));
      b1.setB1("b1.B1");
      session.save(b1);
      
      C c1 = new C();
      CKey ckey = new CKey();
      ckey.setA3("a1.A3");
      ckey.setA4("a1.A4");
      c1.setCKey(ckey);
      c1.setC1("c1.C1");
      session.save(c1);
      
      A a1 = new A();
      a1.setA1(new Long(1234));
      a1.setA3("a1.A3");
      a1.setA4("a1.A4");
      a1.setB(b1);
      a1.setC(c1);
      session.save(a1);
      
      
      tx.commit();
      session.close();
      
      
   }

   public void testUnresolvableObjectExceptionTest() throws Exception {

      Session session = getSession();

      logger.info("Test Starting.........");
      String sql = "from A as a left join fetch a.c where a.a1 = :a1";
      Query query = session.createQuery(sql);
      query.setParameter("a1", new Long(1234));
      List list = query.list();
      for (Iterator i = list.iterator(); i.hasNext();) {
         A a = (A) i.next();
         System.out.println(a.getA1() + " " + a.getA3() + " " + a.getA4());
      }
      logger.info("Test Completed Successfully");
   }

   private Session getSession() throws Exception {

      if (sessionFactory == null) {
         Configuration cfg = new Configuration()
         .addResource("test/uoe/Mapping.hbm.xml")
         .setProperty("hibernate.connection.driver_class","org.hsqldb.jdbcDriver")
         .setProperty("hibernate.connection.url", "jdbc:hsqldb:.")
         .setProperty("hibernate.dialect", "net.sf.hibernate.dialect.HSQLDialect")
         .setProperty("hibernate.connection.username", "sa")
         .setProperty("hibernate.connection.password", "")
         .setProperty("hibernate.connection.autocommit", "false")
         .setProperty("hibernate.show_sql", "true")
         .setProperty("hibernate.hbm2ddl.auto", "create-drop");

         sessionFactory = cfg.buildSessionFactory();
      }
      return sessionFactory.openSession();
   }
}


Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="test.uoe" >
  <class name="A" table="A" mutable="false">
    <id name="a1" column="A1" type="java.lang.Long">
      <generator class="assigned"/>
    </id>
    <many-to-one class="B" name="b" column="A2" not-null="false" outer-join="false" insert="false"/>
    <property name="a3" column="A3" type="string" />
    <property name="a4" column="A4" type="string" />       
    <many-to-one class="C" name="c" not-null="false" outer-join="true" insert="false" update="false">
      <column name="A3"/>
      <column name="A4" />
    </many-to-one>
  </class>
 
  <class name="B" table="b">
    <id name="id" column="A2" type="java.lang.Long">
      <generator class="assigned"/>
    </id>
    <property name="b1" column="B1" type="string"/>
  </class>
  <class name="C" table="c">
    <composite-id class="CKey" name="CKey">
      <key-property name="a3" column="A3" type="string"/>
      <key-property name="a4" column="A4" type="string"/>
    </composite-id>
    <property name="c1" column="C1" type="string"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 4:32 pm 
Newbie

Joined: Thu May 12, 2005 5:41 pm
Posts: 3
pksiv wrote:

I just built a test case around your mapping file and it worked fine for me. (Although I'm using 2.1.8 and hsqldb 1.7.2.)


In this test case, that is true.

In the scenario I was working with, there was no mathcing record in table C for A1 = 1234. This resulted in the exception.
Since I was using left outer join fetch, I thought this scenario will be taken care of.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 13, 2005 4:57 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
srhmlpt wrote:
pksiv wrote:

I just built a test case around your mapping file and it worked fine for me. (Although I'm using 2.1.8 and hsqldb 1.7.2.)


In this test case, that is true.

In the scenario I was working with, there was no mathcing record in table C for A1 = 1234. This resulted in the exception.
Since I was using left outer join fetch, I thought this scenario will be taken care of.


Sorry. I missed that part.


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