how to always prepend schema name in jpql - jpa - jpa

I have tables across 3 different database schemas. JPA confuses itself because it tries to find the table at the wrong schema.
I know I can specify the schema at the #Table annotation but, one of the schemas varies and I can't block it's name.
So, my idea is to tell JPA to always prepend the schema name in the queries it creates, whether I define it or not in the #Table annotation.
Is this possible?
Any other solution?
Thanks!
Note: I'm not using Hibernate, I'm using Toplink.

Use a JPA orm.xml and define the schema/catalog in there in the global section. Works fine with DataNucleus JPA when you do that.

Talk to your DBA to see if he can create a schema that will merge all three schemas. That way your application will only have to deal with one schema. DB2 for zOS can do this and it saved having to create different orm.xml files for each environment.

Related

Is it necessary to define entity file of the table if table already exists in typeorm(btw I am using postgres if it matters)?

If it is not necessary can anyone tell me the way? because I want to test a Typeorm query which actually has a lot of tables connected to it? defining all the tables will take a lot of time?

Is there a way to setup code generation in JOOQ for multiple schemas with the same table structure?

We have a multi-tenant database, where each tenant has their own dedicated schema. The schemas always have identical table structures. What I'm trying to figure out is if there's a way to pass the schema to JOOQ at query time when using code generation to track the schema. Something like:
dslContext.useSchema("schema1").select(A.id).from(A).fetch()
It seems like the schema is always tied to the table object and the only option for mapping at runtime is statically via an input schema and an output schema.
Environmental info: Java/Kotlin, Maven, Spring Boot, Postgres, Flyway
The features you are looking for are:
Code generation time schema mapping
Runtime schema mapping
See also the FAQ
The simplest solution here is to just turn off the generation of schema information in the code generator:
<outputSchemaToDefault>true</outputSchemaToDefault>
Or at runtime
new Settings().withRenderSchema(false);

How to refer two schemas in single entity using ejb

I want to use two different schema in database, each schema has same set of Tables but data differs. How to use same entity two point different schemas in ejb.
Thanks in advance

Eclipse JPA Tools generating duplicate fields in Generate Entities from Tables

JPA Tools -> Generate Entities from Tables... results in duplicate fields:
Predictably this results in this:
Not shown are all the duplicated getters and setters. Deleting them is a pain, even for a small class like this.
I cannot see any easy option to fix this. Does anyone have any ideas why it's happening? Thanks in advance.
This is true for mysql. I had three identical schemas with the same user table on mysql database instance. The entity created by the JPA Tools plugin had multiple fields with same name mapped to the multiple user tables in various schemas. Once I deleted all but one schema on the database, the tool retrieved correct list of fields that mapped to columns on the table
I had the same issue. I just renamed the other table in another schema. It seems that the Generate Entities from Table in Eclipse for a MySQL database looks for all tables with the same name no matter the schema.

Map multiple tables to a single entity dynamically

I have some tables which should add to my database every year and name of databases contains the year (like sell2005) and iv'e written some ef queries on these tables ,and queries can only be on a single entity (like sell2005) but what should i do when sell2006 or sell2007 add ? how can i manage them with that single query which iv'e written before?
thank you.
There is no easy way. EF is simply not tool for this scenario. For EF you must have "single table" so you must either use partitioning with one real database table partitioned by year or you must build a view on top of these tables.
The problem is that in EF you have strict relation between classes and tables. You cannot have single class mapped to multiple tables even if they are exactly same (except inheritance which is not solution for you). So the workaround would require to have multiple SSDL/MSL mappings - one for each table and construct correct context instance with correct mapping for every query. As I know dynamic changes of mapping are not possible (except modifying SSDL/MSL files before using them).