-->
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: Why do I get UnresolvableObjectException???
PostPosted: Wed May 26, 2004 8:45 am 
Newbie

Joined: Tue May 18, 2004 10:47 am
Posts: 5
Hello,
I am using Hibernate 2.1.3.
Following is the portion of the mapping file.
========================================
<class name="Prospect" table="MIS_PROSPECTS">
<id name="id" column="PRP_PROSPECT_ID">
<generator class="native"/>
</id>
<property name="companyName" column="PRP_COMPANY_NAME" type="string" not-null="true"/>
<property name="corpAddr1" column="PRP_CORP_ADDRESS_1" type="string"/>
<property name="corpAddr2" column="PRP_CORP_ADDRESS_2" type="string"/>
<property name="corpCity"
column="PRP_CORP_CITY" type="string"/>
<property name="corpState" column="PRP_CORP_STATE" type="string"/>
<property name="corpZipCode" column="PRP_CORP_ZIP" type="string"/>
<property name="corpPhone" column="PRP_CORP_PHONE" type="string"/>
<property name="contractCount" column="PRP_CONTRACT_CNT"/>
<set name="groups" table="MIS_PROSPECT_GROUPS">
<key column="PRP_PROSPECT_ID"/>
<one-to-many class="Group"/>
</set>
<many-to-one name="contact" column="CNT_CONTACT_ID" class="Contact" outer-join="auto"/>
</class>
<!-- Contact -->
<class name="Contact" table="MIS_CONTACTS">
<id name="id" column="CNT_CONTACT_ID">
<generator class="native"/>
</id>
<property name="firstName" column="CNT_FIRST_NAME" type="string" not-null="true"/>
<property name="lastName" column="CNT_LAST_NAME" type="string" not-null="true"/>
<many-to-one name="contactType" column="CTR_CONTACT_TYPE" class="ContactType" unique="true"/>
</class>
=================================

Following is the java code:
=================================
public void getProspectByCity(String criteria) {
Session sess = null;
try {
sess = sessFactory.openSession();
Transaction tx = null;
List prospects = null;
tx = sess.beginTransaction();
Query q = sess.createQuery("from Prospect as prospect " +
"left join fetch prospect.contact where " +
"prospect.corpCity like :city");
String likeCity = criteria + "%";
q.setString("city", likeCity);
prospects = q.list();
Prospect prospect = (Prospect) prospects.get(0);
Iterator itr = prospect.getGroups().iterator();
Group nextGroup = null;
while (itr.hasNext()) {
nextGroup = (Group) itr.next();
System.out.println("Group - id = "

+nextGroup.getGroupNumber());
}
tx.commit();
}
catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
try {
if ((sess != null) && (sess.isOpen())) {
sess.close();
}
}
catch (HibernateException e1) {
e1.printStackTrace();
}
}
}
=================================

follwing is the stack trace:
==================================
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 605811, of class:

com.ibx.ecommerce.persist.Contact
at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java(Compiled Code))
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java(Inlined Compiled Code))
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java(Compiled Code))
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java(Compiled Code))
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java(Compiled Code))
at net.sf.hibernate.loader.Loader.doQuery(Loader.java(Compiled Code))
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at com.ibx.ecommerce.persist.InitialTester.getProspectByCity(InitialTester.java:136)
at com.ibx.ecommerce.persist.InitialTester.main(InitialTester.java:166)
=====================================
I have turned on "show_sql" to try to understand what is going on.
==============================================

Hibernate: select prospect0_.PRP_PROSPECT_ID as PRP_PROS1_, prospect0_.PRP_COMPANY_NAME as PRP_COMP2_,

prospect0_.PRP_CORP_ADDRESS_1 as PRP_CORP3_, prospect0_.PRP_CORP_ADDRESS_2 as PRP_CORP4_, prospect0_.PRP_CORP_CITY

as PRP_CORP5_, prospect0_.PRP_CORP_STATE as PRP_CORP6_, prospect0_.PRP_CORP_ZIP as PRP_CORP7_,

prospect0_.PRP_CORP_PHONE as PRP_CORP8_, prospect0_.PRP_CONTRACT_CNT as PRP_CONT9_, prospect0_.CNT_CONTACT_ID as

CNT_CON10_ from MIS2.MIS_PROSPECTS prospect0_ left outer join MIS2.MIS_CONTACTS contact1_ on

prospect0_.CNT_CONTACT_ID=contact1_.CNT_CONTACT_ID where (prospect0_.PRP_CORP_CITY like ? )
Hibernate: select contact0_.CNT_CONTACT_ID as CNT_CONT1_1_, contact0_.CNT_FIRST_NAME as CNT_FIRS2_1_,

contact0_.CNT_LAST_NAME as CNT_LAST3_1_, contact0_.CTR_CONTACT_TYPE as CTR_CONT4_1_, contacttyp1_.CTR_CONTACT_TYPE

as CTR_CONT1_0_, contacttyp1_.CTR_DESCRIPTION as CTR_DESC2_0_ from MIS2.MIS_CONTACTS contact0_ left outer join

MIS2.MIS_CONTACT_TYPE_REF contacttyp1_ on contact0_.CTR_CONTACT_TYPE=contacttyp1_.CTR_CONTACT_TYPE where

contact0_.CNT_CONTACT_ID=?
Hibernate: select contact0_.CNT_CONTACT_ID as CNT_CONT1_1_, contact0_.CNT_FIRST_NAME as CNT_FIRS2_1_,

contact0_.CNT_LAST_NAME as CNT_LAST3_1_, contact0_.CTR_CONTACT_TYPE as CTR_CONT4_1_, contacttyp1_.CTR_CONTACT_TYPE

as CTR_CONT1_0_, contacttyp1_.CTR_DESCRIPTION as CTR_DESC2_0_ from MIS2.MIS_CONTACTS contact0_ left outer join

MIS2.MIS_CONTACT_TYPE_REF contacttyp1_ on contact0_.CTR_CONTACT_TYPE=contacttyp1_.CTR_CONTACT_TYPE where

contact0_.CNT_CONTACT_ID=?
============================
=====================================
I get the UnresolvableObjectException on the "q.list()".
I assumed the left outer join would handle the problem of a row in the
prospects table having a contact column value that doesn't exist as a FK in the contacts table.

HOW CAN I AVOID THIS EXCEPTION????


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.