Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » JPA 2.0 BUG
icon8.gif  JPA 2.0 BUG [message #504097] Thu, 17 December 2009 04:06 Go to next message
Eclipse UserFriend
Hi,

J2EE 6 JPA 2.0 API specifies that EntityManager's find(java.lang.Class<T> entityClass, java.lang.Object primaryKey) method must return null if the entity does not exist .

However EclipseLink's implementation throws java.lang.IllegalArgumentException even though both arguments are valid
Re: JPA 2.0 BUG [message #504102 is a reply to message #504097] Thu, 17 December 2009 04:24 Go to previous messageGo to next message
Eclipse UserFriend
> J2EE 6 JPA 2.0 API specifies that EntityManager's
> find(java.lang.Class<T> entityClass, java.lang.Object primaryKey) method
> must return null if the entity does not exist .
>
> However EclipseLink's implementation throws
> java.lang.IllegalArgumentException even though both arguments are valid

OH! Really? Interesting. I already wrote a utility method to convert the exception to null.
Re: JPA 2.0 BUG [message #504218 is a reply to message #504102] Thu, 17 December 2009 12:43 Go to previous messageGo to next message
Eclipse UserFriend
In my testing I get null back from find when the PK value(s) passed in are not found in the database.

I do get an IllegalArgumentException exception if the attribute type passed to find is not exactly the same as the type defined in the class.

Doug
Re: JPA 2.0 BUG [message #504253 is a reply to message #504218] Thu, 17 December 2009 16:42 Go to previous messageGo to next message
Eclipse UserFriend
> In my testing I get null back from find when the PK value(s) passed in
> are not found in the database.
> I do get an IllegalArgumentException exception if the attribute type
> passed to find is not exactly the same as the type defined in the class.

Well, I have to confirm Cristi; I replaced the getSingleResult calls with this utility method, using getResultList (throwing an exception is considered heavy, so I decided to go for the list):

/**
* getSingleResult throws an exception if nothing is found.
*
* @param lQuery
* @return
*/
static public Object getSingleResultOrNull(Query lQuery)
{
java.util.List lList = lQuery.getResultList();
if (lList.size() == 0) return null;
Object o = lList.get(0);
return o;
}

Naturally I can retest, but at the very least this was the case indeed.
Re: JPA 2.0 BUG [message #505724 is a reply to message #504253] Mon, 04 January 2010 11:35 Go to previous messageGo to next message
Eclipse UserFriend
I am a little confused. There seems to be two issues in this thread.

1. em.find will return null for a non existent entity assuming the identity type matches that of the mapped entity class.

2. query.getSingleResult() will thrown an exception if no entity is found executing the query.

If you have a case where em.find throws an IllegalArgumentException and the both the entity type and id type are valid then please log a bug with the example and we'll address it.

Cheers,

Doug
Re: JPA 2.0 BUG [message #505742 is a reply to message #505724] Mon, 04 January 2010 12:55 Go to previous message
Eclipse UserFriend
On 2010-01-04 17:35, Doug Clarke wrote:
> I am a little confused. There seems to be two issues in this thread.
>
> 1. em.find will return null for a non existent entity assuming the
> identity type matches that of the mapped entity class.
>
> 2. query.getSingleResult() will thrown an exception if no entity is
> found executing the query.
>

Oh my, you are so right. My static find methods used to use getSingleResult; so I was confused and mixed up my find with EM's find.

Tom
Previous Topic:NoSuchMethodException when using FetchType.Lazy and weaving
Next Topic:Workbench and Object-relational nested table mappings
Goto Forum:
  


Current Time: Wed Jul 23 14:19:21 EDT 2025

Powered by FUDForum. Page generated in 0.05110 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top