ObjectDB ObjectDB

First query before any of the object has been stored

#1

I have some code that, before writing an object via ObjectDB makes a query to ensure the new object is different from what's already stored.  The problem is that, before any instances of that object have been stored, the query generates an exception.  I'd been expecting NoResultException to be thrown, and coded to handle that as an empty result.

What's really getting thrown is the more general PersistenceException, with a message that says "Type Blah wasn't found".  

Is this expected behavior?  

If it is, I don't really want to parse the exception message to work out if it's this situation or some other persistence related exception.  How can I know if any of an object has been stored yet?

edit
delete
#2

The query fails because the database doesn't have the entity class yet (no instances of that class have been persisted yet), and a persistence unit is not defined.

Either define a persistence unit or introduce the class to ObjectDB before the query, for example by:

    em.getMetamodel().entity(User.class);
ObjectDB Support
edit
delete
#3

Thanks!  That worked great.

edit
delete

Reply

To post on this website please sign in.