How to refer two schemas in single entity using ejb - jpa

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

Related

CREATE POSTGRESQL Entity Relationship Model

I desperately need your help. I have database tables IN POSTGRESQL which I need to create an ER Model for them. My challenge is creating relationships among the tables. I know this might be alot of work but I just need help on creating relationships among the tables, what column names should I use and all that . Here is an image of the tables in the database

join table between 2 persistance unit

I have two different persistence units in my application. I'm using JPA 2.0 as ejb3.0 as my entity provider. In one of my database schemas, I have a table which contains a column which has a foreign key relationship to a table in the other schema. These tables are mapped as separate entities in my code with no relationship. Is it possible to construct a named query to join across these two schemas?
across 2 schemas, yes.
across 2 persistence units no, since anything referenced has to be present in the persistence unit.
No reason why a persistence unit can't have entities from 2 schemas

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).

how to always prepend schema name in jpql - 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.

one or more Entity models for one database for entity framework?

When use entity framework for DAL tier, VS 2010 can create edmx for each database.
Question:
If I have a database with many tables, should I create only one edmx for all tables or mutiple edmx files? for example, maybe all security tables for one edmx file, other tables for another edmx file. If there is more than one, then in other tiers, there will have more then on ObjectContext in code for business logic.
Which one it the best solution for this case?
I've done this before when experimenting with AdventureWorks. If you have a large database with lots of tables, and the tables are segmented into separate schemas (like the Purchasing, Sales, HumanResources schemas in AdventureWorks) then it may work well to create multiple models. They don't have to be separate schemas- any two groups of related tables where there are no relations between the groups would work.
You'd want to make sure that you include all related tables in each model so that you don't have to try to join entities across models.