You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by kojak <ke...@gmail.com> on 2011/03/03 18:54:17 UTC

How to Specify the Schema for a Named Query

Hi,

I am using Apache Derby with OpenJPA and have a class with a named query. 
Unfortunately, every time I attempt to execute the named query I get an
error because OpenJPA is assuming the "USER" schema.  The "USER" schema is
not the default for Derby.  It is "APP" I think.  This does not happen when
I do not use a named query.

Here are my persistence.xml properties:
			openjpa.ConnectionURL=jdbc:derby:databases/JPATest;create=true				
			openjpa.ConnectionUserName=user
			openjpa.ConnectionPassword=password
			openjpa.ConnectionDriverName=org.apache.derby.jdbc.EmbeddedDriver
			openjpa.jdbc.Schema=APP
		
openjpa.jdbc.SynchronizeMappings=buildSchema(SchemaAction='add,deleteTableContents')


Here is my first test with a native query...

  @Entity
  @NamedNativeQuery(name = "getByID",  
  		resultClass = com.mycompany.Employee.class, 
		query = "SELECT x FROM Employee x WHERE x.id = ?1")
  @Cacheable
  @Table(schema = "APP")
  public class Employee{

Here is the code to execute the query:
  Query q = em.createNamedQuery("getByID");
  q.setParameter(1, rand);

Here is the error:
Exception in thread "main" 
org.apache.openjpa.persistence.PersistenceException: Schema 'USER' does not
exist {SELECT x FROM Employee x WHERE x.id = ?} [code=30000, state=42Y07]

--
View this message in context: http://openjpa.208410.n2.nabble.com/How-to-Specify-the-Schema-for-a-Named-Query-tp6085743p6085743.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How to Specify the Schema for a Named Query

Posted by Rick Curtis <cu...@gmail.com>.
Please take a look through this[1] old post. It looks quite similar.

[1] http://openjpa.markmail.org/thread/okfgmc2ldwkxrst6

Thanks,
Rick

On Thu, Mar 3, 2011 at 11:54 AM, kojak <ke...@gmail.com> wrote:

> Hi,
>
> I am using Apache Derby with OpenJPA and have a class with a named query.
> Unfortunately, every time I attempt to execute the named query I get an
> error because OpenJPA is assuming the "USER" schema.  The "USER" schema is
> not the default for Derby.  It is "APP" I think.  This does not happen when
> I do not use a named query.
>
> Here are my persistence.xml properties:
>
>  openjpa.ConnectionURL=jdbc:derby:databases/JPATest;create=true
>                        openjpa.ConnectionUserName=user
>                        openjpa.ConnectionPassword=password
>
>  openjpa.ConnectionDriverName=org.apache.derby.jdbc.EmbeddedDriver
>                        openjpa.jdbc.Schema=APP
>
>
> openjpa.jdbc.SynchronizeMappings=buildSchema(SchemaAction='add,deleteTableContents')
>
>
> Here is my first test with a native query...
>
>  @Entity
>  @NamedNativeQuery(name = "getByID",
>                resultClass = com.mycompany.Employee.class,
>                query = "SELECT x FROM Employee x WHERE x.id = ?1")
>  @Cacheable
>  @Table(schema = "APP")
>  public class Employee{
>
> Here is the code to execute the query:
>  Query q = em.createNamedQuery("getByID");
>  q.setParameter(1, rand);
>
> Here is the error:
> Exception in thread "main"
> org.apache.openjpa.persistence.PersistenceException: Schema 'USER' does not
> exist {SELECT x FROM Employee x WHERE x.id = ?} [code=30000, state=42Y07]
>