Hibernate: overriding the hibernate.default_schema property in persistence.xml

I have my default schema declared in persistence.xml as:

<property name="hibernate.default_schema" value="MYSCHEMA" /> 

However, now I want to access a single table from CURRSCHEMA, which is in the same database.

An entity is created as "Currency for Curreny table" in CURRSCHEMA.

But running the following query tries to access MYSCHEMA.Currency, which leads to an error.

 // here will go the code to fetch currency String currencySql = "select C.pk.currCode from Currency C where C.pk.idCode = :idCode"; Query currencyQuery = this.em.createQuery(currencySql); currencyQuery.setParameter("idCode", "CCY"); 

My objects use annotations:

 @Entity @Table(name="CURRENCY") public class Currency implements Serializable { 

Changing @Table (name = "CURRENCY") to @Table (name = "CURRSCHEMA.CURRENCY") does not work.

How to do it?

+4
source share
1 answer

Have you tried @Table(schema = "CURRSCHEMA", name = "CURRENCY") ?

+11
source

Source: https://habr.com/ru/post/1381616/


All Articles