-->
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: Single-entity finder exception handling
PostPosted: Tue Nov 08, 2005 10:21 am 
Newbie

Joined: Fri Apr 08, 2005 7:15 am
Posts: 10
Hello,

The EJB spec version 3.0 public draft does not contain detailed information on the different types of exceptions and the exception handling strategies but I noticed the following discrepancy:

Page 38 describes the find operation on the EntityManager interface:
Code:
/**
  * Find by primary key.
  * @param entityClass
  * @param primaryKey
  * @return the found entity instance or null
  * if the entity does not exist
  * @throws IllegalArgumentException if the first argument does
  * not denote an entity type or the second
  * argument is not a valid type for that
  * entity’s primary key
  */
public <T> T find(Class<T> entityClass, Object primaryKey);


Page 50 describes the getSingleResult operation on the Query interface:
Code:
/**
  * Execute a SELECT query that returns a single result.
  * @return the result
  * @throws EntityNotFoundException if there is no result
  * @throws NonUniqueResultException if more than one result
  * @throws IllegalStateException if called for an EJB QL
  * UPDATE or DELETE statement
  */
public Object getSingleResult();


Why does the find method return null if the entity does not exist, whereas the getSingleResult operation throws an EntityNotFoundException if there is no result?

Kind regards,
Stijn Janssens


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 7:51 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
this is expected. SingleREsult means exactly 1, find mean 0 or 1

_________________
Emmanuel


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.