Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate: Overriding hibernate.default_schema property in persistence.xml

Tags:

hibernate

jpa

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

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

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

Entity is created as say Currency for Curreny table in CURRSCHEMA.

But running the below query tries to access MYSCHEMA.Currency which results in 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 entities are using annotations:

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

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

How to go about this ?

like image 507
Vicky Avatar asked Dec 27 '22 11:12

Vicky


1 Answers

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

like image 125
axtavt Avatar answered Dec 30 '22 10:12

axtavt