Search code examples
javasqlpostgresqlcriteriacriteria-api

How to exclude db name from criteria builder?


I am trying to get data from msSQLDB (if this is relevant) and while doing it I encountered an issue. What I want is to exclude db name from a query, it should look like that:

Select ... from CLASS2 ...

But what I am getting is:

Select ... from db1.CLASS2 ...

This is somewhat legacy project, so it is not possible to change architecture.

It worked on Oracle -> WL -> SQL Server database but on current spec: PostgreSQL -> Tomcat -> SQL Server database it does not. Not sure if I provided enough data to work with, so I can provide more details if needed.

@Table(name = 'CLASS') //table from db1
class CLASS1 exstends SUPERCLASS {
 //empty
}
@Table(name = 'CLASS2') //table from db2
class CLASS2 exstends SUPERCLASS {
//empty
}

@MappedSuperclass
class SUPERLASS {
//fields here

public static List<CLASS1> getData(ConnectionToken ct) {
CriteriaBuilder cb = ct.getCriteriaBuilder();
CriteriaQuery query = cb.createQuery(CLASS1.class);
Root<CLASS2.class) = query.from(CLASS2.class)
query.where ...
return ...

}
}

Solution

  • It appears to be quite trivial, i just forgot that i can do that. In @TABLE annotation i just added "schema" parameter @Table(name = 'CLASS2' shema='db2')