0

I am using OpenJPA in my work. Sometimes I have to use JPQL and sometimes I have to use native query(em.createNativQuery).

I am witnessing a big issue with native query. I have to provide schema name too.

Like for JPQL I can write:

em.createQuery("Select e from Entity_name e").getResultList();

But in case of native query I need to do:

em.createNativeQuery("Select e from SCHEMANAME.Table_name e").getResultList()

Why is it so?And isn't this wrong behaviour as schema name may vary with time.

tharindu_DG
  • 8,900
  • 6
  • 52
  • 64
Mandroid
  • 6,200
  • 12
  • 64
  • 134

1 Answers1

0

Try specifying the following property in your configuration.

<property name="openjpa.jdbc.Schema" value="SCHEMANAME"/>

If you use both JPQL and native queries, try to add the actual entity as follows.

e.g Query query = em.createNativeQuery("SELECT * FROM MAG", Magazine.class);

Otherwise you might face data inconsistency issues like dirty reads, lost updates .etc

UPDATE

Query createNativeQuery(java.lang.String sqlString,
                        java.lang.Class resultClass)

Create an instance of Query for executing a native SQL query.

Parameters: sqlString - a native SQL query string

resultClass - the class of the resulting instance(s)

Hope this helps.

tharindu_DG
  • 8,900
  • 6
  • 52
  • 64