-->
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: object returned while it doesn't exist , getId throws except
PostPosted: Wed Mar 08, 2006 8:33 am 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.2

Hello,

When i query any object by an id that does not exist I do get back a proxy object. On that object I cannot call methods because the object does not exist in the database. I dont know how to handle this since object==null returns false but when i want do something with the object my application crashes saying that the object cannot be found. Why dont I get back a null object?

regards,
Dennis


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 9:35 am 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:16 am
Posts: 44
Location: Bangalore
Hi,
Can you post the code, HBM files and the exact exception you are getting? That might help us. :-)

_________________
Please vote if my Postings helps. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 12:11 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
the code:

Criteria criteria = getCriteria();
criteria.add(Restrictions.eq("id", new Long(id)));
Object uniqueResult = criteria.uniqueResult();

the mapping:

<hibernate-mapping>
<class
name="com.xxiro.persistance.domain.impl.User"
table="user"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="ID"
type="long"
unsaved-value="null"
>
<generator class="identity">
</generator>
</id>

<version
name="version"
type="integer"
column="VERSION"
/>

<set
name="tags"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="USER_ID"
/>

<one-to-many
class="com.xxiro.persistance.domain.impl.Tag"
/>
</set>

<set
name="userHistory"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="USER_ID"
/>

<one-to-many
class="com.xxiro.persistance.domain.impl.UserHistory"
/>
</set>

<set
name="serviceUsers"
lazy="true"
inverse="true"
cascade="delete"
sort="unsorted"
>

<key
column="USER_ID"
/>

<one-to-many
class="com.xxiro.persistance.domain.impl.ServiceUser"
/>
</set>

<set
name="cardOrders"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>

<key
column="USER_ID"
/>

<one-to-many
class="com.xxiro.persistance.domain.impl.CardOrder"
/>
</set>

<set
name="officeUsers"
lazy="true"
inverse="true"
cascade="delete"
sort="unsorted"
>

<key
column="USER_ID"
/>

<one-to-many
class="com.xxiro.persistance.domain.impl.OfficeUser"
/>
</set>

<set
name="timeTableUsers"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="USER_ID"
/>

<one-to-many
class="com.xxiro.persistance.domain.impl.TimetableUser"
/>
</set>

<property
name="address"
type="java.lang.String"
update="true"
insert="true"
column="ADDRESS"
length="128"
not-null="true"
/>

<property
name="addressNumber"
type="java.lang.Integer"
update="true"
insert="true"
column="ADDRESS_NUMBER"
not-null="true"
/>

<property
name="addressNumberAdd"
type="java.lang.String"
update="true"
insert="true"
column="ADDRESS_NUMBER_ADD"
length="16"
not-null="false"
/>

<property
name="postalcode"
type="java.lang.String"
update="true"
insert="true"
column="POSTAL_CODE"
length="6"
not-null="true"
/>

<property
name="city"
type="java.lang.String"
update="true"
insert="true"
column="CITY"
length="64"
not-null="true"
/>

<property
name="country"
type="java.lang.String"
update="true"
insert="true"
column="COUNTRY"
length="64"
not-null="true"
/>

<property
name="blocked"
type="boolean"
update="true"
insert="true"
column="BLOCKED"
/>

<property
name="state"
type="short"
update="true"
insert="true"
column="STATE"
/>

<property
name="initials"
type="java.lang.String"
update="true"
insert="true"
column="INITIALS"
length="16"
not-null="true"
/>

<property
name="firstName"
type="java.lang.String"
update="true"
insert="true"
column="FIRST_NAME"
length="32"
not-null="true"
/>

<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
column="LAST_NAME"
length="64"
not-null="true"
/>

<property
name="callName"
type="java.lang.String"
update="true"
insert="true"
column="CALL_NAME"
length="64"
not-null="false"
/>

<property
name="prefix"
type="java.lang.String"
update="true"
insert="true"
column="PREFIX"
length="16"
not-null="false"
/>

<property
name="gender"
type="java.lang.Character"
update="true"
insert="true"
column="GENDER"
not-null="true"
/>

<property
name="dateOfBirth"
type="java.util.Date"
update="true"
insert="true"
column="DATE_OF_BIRTH"
not-null="true"
/>

<property
name="nationality"
type="java.lang.String"
update="true"
insert="true"
column="NATIONALITY"
length="64"
not-null="false"
/>

<property
name="email"
type="java.lang.String"
update="true"
insert="true"
column="EMAIL"
length="64"
not-null="false"
unique="true"
/>

<property
name="username"
type="java.lang.String"
update="true"
insert="true"
column="USERNAME"
length="64"
not-null="true"
unique="true"
/>

<property
name="password"
type="java.lang.String"
update="true"
insert="true"
column="PASSWORD"
length="64"
not-null="true"
unique="false"
/>

<property
name="pincode"
type="java.lang.String"
update="true"
insert="true"
column="PINCODE"
length="64"
not-null="true"
unique="false"
/>

<property
name="mobilePhone"
type="java.lang.String"
update="true"
insert="true"
column="MOBILE_PHONE"
length="16"
not-null="false"
/>

<property
name="phone"
type="java.lang.String"
update="true"
insert="true"
column="PHONE"
length="16"
not-null="false"
/>

<property
name="fax"
type="java.lang.String"
update="true"
insert="true"
column="FAX"
length="16"
not-null="false"
/>

<property
name="remark"
type="java.lang.String"
update="true"
insert="true"
column="REMARK"
not-null="false"
/>

<property
name="bankAccount"
type="java.lang.String"
update="true"
insert="true"
column="BANK_ACCOUNT"
length="30"
not-null="false"
/>

<property
name="payMethod"
type="java.lang.Integer"
update="true"
insert="true"
column="PAY_METHOD"
not-null="false"
/>

<property
name="photoLastUpdated"
type="java.util.Date"
update="true"
insert="true"
column="PHOTO_LAST_UPDATED"
not-null="false"
/>
</class>

The exception :

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.xxiro.persistance.domain.impl.Card#8658768768768]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 2:18 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
am i the only one that ever got this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 2:12 pm 
Beginner
Beginner

Joined: Thu Oct 27, 2005 11:53 am
Posts: 42
Just found out in another post that i use load instead of get, that is the reason an object is returned while it doesn't exist.


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.