-->
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: EntityNotFoundException
PostPosted: Mon Sep 15, 2008 9:35 am 
Newbie

Joined: Mon Sep 15, 2008 8:37 am
Posts: 9
Hi! I get an EntityNotFoundException from the EntityManager.find()-Method. I've the following DB structure:
:

Table "Order":
-id
-myClassId

Table "MyClasses":

-id

My POJOs look like:

Order
{
int id;
MyClass myClass;
}

MyClass
{
int id;
}

In case when no MyClass is defined for an Order, the field myClassId hat the Integer value 0 (not NULL).

When calling the find()-method Hibernate finds an order which has no MyClass difined (myClassId has the value 0). Hibernate tries to find a MyClass in the table MyClasses, finds nothing and throws an EntityNotFoundException. But I want to get an Order object with a null pointer in the variable myClass in such cases.

Which ways are there to achieve that? Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 8:55 am 
Newbie

Joined: Mon Sep 15, 2008 8:37 am
Posts: 9
I've figured out how to solve the problem. There is a Hibernate annotation @org.hibernate.NotFound. Setting action = NotFoundAction.IGNORE makes Hibernate set a null pointer to myClass variable instead of throwing the EntityNotFoundException.

The funny thing about this story is when you have the action = NotFoundAction.Exception being set, Hibernate distinguishes between 2 cases:

1)FetchType.EAGER: The EntityNotFoundException is being thrown
2)FetchType.Lazy: myClass variable references an empty MyClass-object

Have anyone an idea why?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 9:07 am 
Newbie

Joined: Mon Sep 15, 2008 8:37 am
Posts: 9
I've another question: I'm using java persistence api and i'd like to be undependant from the persistence provider. Has anyone an idea how to achieve that using by means of JPA (without using Hibernate annotation)?


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.