-->
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: Many-To-One association throwing ObjectNotFoundException
PostPosted: Tue Jan 31, 2006 9:38 am 
Beginner
Beginner

Joined: Tue Dec 21, 2004 11:53 am
Posts: 42
Hibernate version: 3.1.1

Hello there! I have three entities:

Subscriber
Product
Package

Subscriber has a one-to-many relationship to Product (mapped as a Set)
and Product has a many-to-one relation ship to packate Package


What's happening (Ok I'm affraid it might be an constraint violation of the DB, but please read on...)
Subscriber has 3 products 2 of them have a corresponding row on the Package table, a third one does not.

Well, hibernate is throwing an ObjectNotFoundException. My question is shouldn't it be using get instead of load for this relationship? I'd like to have a partial filled collection instead an error, what could be done to solve this?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 10:02 am 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

Sounds like you have a database problem there.

My solution:

Unmap de many to one relation, simply map the packageId as a Long or String or whatever it is in Product class.

Package package= (Package) hibernateSession.get(Package.class, product.getPackageId());
if (product.getPackageId() != null && package== null) {
// log if database inconsistency
logger.warn("You just discovered a database inconsistency");
}

If your case the result should be:

1 Subscriber
3 Product
2 Package
1 warn message

For more help pls ask.


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.