ObjectDB ObjectDB

Type xxx is not found (error 301)

#1

The error:

Type User is not found (error 301)

occurs when I query the db for a type before any instances of that type have been persisted, e.g.:

return em.createQuery ("SELECT a FROM User a").getResultList ();

What I was expecting was an empty list, not an error.

Is there some enhancement that should be done beforehand?

 

edit
delete
#2

I think what I'm asking is whether there is a JPA equivalent of the JDO getExtent() method?

edit
delete
#3

Your observation is correct - this is the result of querying a class with no instances in the database.

In standard JPA the solution is to list all the managed classes in advance.

In ObjectDB you can also introduce the new class before query execution by using:

    em.find(User.class, User.class);

but this is not a portable JPA code.

Update (starting ObjectDB 2.2): em.getMetamodel().entity(User.class) is preferred.

Regarding Extent in JPA, your "SELECT a FROM User a" query is the standard replacement of JPA for JDO extents.

Alternatively, if you want, you may use JDO from JPA application by obtaining PersistenceManager from your EntityManager:

    em.unwrap(PersistenceManager.class).getExtent(User.class)

 

ObjectDB Support
edit
delete
#4

OK, so there are several ways to make classes known to odb:

1) list in persistence.xml (and put this under META-INF)

2) em.fund (User.class, User.class)

3) use jdo from jpa - is there a performance penalty for unwrapping PersistenceManager.class ?

edit
delete
#5

Am not seeing a method:

em.find (class, class), but there is one: em.find (class, object), so, what would the object be?

edit
delete
#6

oddly, I don't have an unwrap() method on my EntityManager??

also, I don't have a query (String, Class) method on my EntityManager

edit
delete
#7

> 3) use jdo from jpa - is there a performance penalty for unwrapping PersistenceManager.class ?

No - it is merely casting.

> Am not seeing a method: em.find (class, class), but there is one: em.find (class, object), so, what would the object be?

Class is also Object so you can send User.class as the 2nd argument.

> oddly, I don't have an unwrap() method on my EntityManager??

> also, I don't have a query (String, Class) method on my EntityManager

Probably you have JPA 1 jpa.jar in your classpath before objectdb.jar - this happens for example if you use old Glassfish version that contains JPA 1.0.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.