• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NoSuchEntityException

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Goodday,

I am using EJB 2.0 CMP Entity beans from within a Session bean.

I am getting a NoSuchEntityException on a given primary key, primaryKey. The code snippet is as follows:

try {
MTCEntityLocal mtcEntityLocal =
mtcEntityLocalHome.findByPrimaryKey(primaryKey);
MTCHistoryLocal mtcHistoryLocal =
mtcHistoryLocalHome.create(primaryKey, mtcEntityLocal);
}
catch (FinderException fe) {
// do something else
}

As you can see, the initialisation of the mtcHistoryLocal is dependent on the retrieval of the mtcEntityLocal entity bean. Therefore, if the entity does not exist we catch the FinderException and do something else.

And most of the time this works fine. In fact, I cannot replicate the problem, so I only have some server logs to go by. These state that a NoSuchEntityException is thrown when a 'get' method is called on mtcEntityLocal within mtcHistoryLocalHome.create(primaryKey, mtcEntityLocal)

I cannot understand why this might be, since there is no way through the application to remove the underlying data record; thus eliminating a concurrency problem.

All beans have <trans-attribute>Required</trans-attribute> in ejb-jar.xml so I'm thinking there should be no transactional problem.

Since the problem is intermittent, I have trouble investigating the state of the data when it occurs; when the problem does occur, a 2nd attempt is successful.

The application server is weblogic 8.1 and the database is Informix (not sure of the version).

Any help much appreciated.

Jim
 
jim cato
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I would like to clarify the situation here.

The MTCEntity bean is related to another entity bean (the MEntity bean) in a 1 to 1 mapping. Here is the relationship mappings from ejb-jar.xml:

<blockquote>code:
<pre name="code" class="core">
<relationships>
<ejb-relation>
<ejb-relation-name>MTCEntity-MEntity</ejb-relation-name>
<ejb-relationship-role>
<description>mtcEntity</description>
<ejb-relationship-role-name>
MTCEntityRelationshipRole
</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<description>MTCEntity</description>
<ejb-name>MTCEntity</ejb-name>
</relationship-role-source>
<cmr-field>
<description>mEntity</description>
<cmr-field-name>mEntity</cmr-field-name>
</cmr-field>
</ejb-relationship-role>

<ejb-relationship-role>
<description>mEntity</description>
<ejb-relationship-role-name>
MEntityRelationshipRole
</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<description>MEntity</description>
<ejb-name>MEntity</ejb-name>
</relationship-role-source>
<cmr-field>
<description>mtcEntity</description>
<cmr-field-name>mtcEntity</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>
</pre>
</blockquote>

So the MTCEntity bean contains a MEntity bean and vice versa.

At the start of the transaction, a new MEntity bean is created (but not committed):

<blockquote>code:
<pre name="code" class="core">
try {
mEntityLocal = mEntityLocalHome.create(primaryKey, mDetails);
} catch (CreateException ce) {
throw new EJBException(ce);
}
</pre>
</blockquote>

This is followed by the code previously listed, where the NoSuchEntityException is thrown in the mtcHistoryLocalHome.create(primaryKey, mtcEntityLocal) method call.

<blockquote>code:
<pre name="code" class="core">
try {
MTCEntityLocal mtcEntityLocal =
mtcEntityLocalHome.findByPrimaryKey(primaryKey);
MTCHistoryLocal mtcHistoryLocal =
mtcHistoryLocalHome.create(primaryKey, mtcEntityLocal);
}
catch (FinderException fe) {
// do something else
}
</pre>
</blockquote>

This is all part of the same transaction, so surely this is no problem. But I am wondering whether there is a chance that the MTCEntity-MEntity relationship is causing confusion such that the mtcEntityLocalHome.findByPrimaryKey(primaryKey) succeeds despite no entity existing.

As you can see I am quite confused, any help gratefully received.
Thanks,
Jim
 
jim cato
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I seem to be talking to myself here, but just in case anyone is watching...

I have managed to replicate the problem, so it seems related to data, but I cannot see why.

I have tried adjusting the transaction attribute to create a seperate transaction for the create of the mEntity like this:

<container-transaction>
<method>
<ejb-name>mEntity</ejb-name>
<method-name>*</method-name>
</method>
</container-transaction>
<container-transaction>
<method>
<ejb-name>mEntity</ejb-name>
<method-name>create</method-name>
</method>
<trans-attribute>RequiresNew</trans-attribute>
</container-transaction>


And it now works fine, so it looks like a transaction problem, but how can this be?

I have also tried creating a DB row for just the mEntity and the mtcEntity finder works as expected by throwing the FinderException.

Still puzzled.

Jim

[ July 17, 2008: Message edited by: jim cato ]
[ July 17, 2008: Message edited by: jim cato ]
 
jim cato
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While I do not understand why this problem occurred, I have managed to circumvent it by using a custom finder method defined in ejb-jar.xml:



This works as expected so maybe there is a bug in the container? Surely not...

Cheers,
James
 
You ought to ventilate your mind and let the cobwebs out of it. Use this cup to catch the tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic